Search in sources :

Example 16 with MmsException

use of com.google.android.mms.MmsException in project qksms by moezbhatti.

the class PduPersister method load.

/**
 * Load a PDU from storage by given Uri.
 *
 * @param uri The Uri of the PDU to be loaded.
 * @return A generic PDU object, it may be cast to dedicated PDU.
 * @throws MmsException Failed to load some fields of a PDU.
 */
public GenericPdu load(Uri uri) throws MmsException {
    GenericPdu pdu = null;
    PduCacheEntry cacheEntry = null;
    int msgBox = 0;
    long threadId = DUMMY_THREAD_ID;
    try {
        synchronized (PDU_CACHE_INSTANCE) {
            if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
                if (LOCAL_LOGV)
                    Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
                try {
                    PDU_CACHE_INSTANCE.wait();
                } catch (InterruptedException e) {
                    Log.e(TAG, "load: ", e);
                }
                cacheEntry = PDU_CACHE_INSTANCE.get(uri);
                if (cacheEntry != null) {
                    return cacheEntry.getPdu();
                }
            }
            // Tell the cache to indicate to other callers that this item
            // is currently being updated.
            PDU_CACHE_INSTANCE.setUpdating(uri, true);
        }
        Cursor c = SqliteWrapper.query(mContext, mContentResolver, uri, PDU_PROJECTION, null, null, null);
        PduHeaders headers = new PduHeaders();
        Set<Entry<Integer, Integer>> set;
        long msgId = ContentUris.parseId(uri);
        try {
            if ((c == null) || (c.getCount() != 1) || !c.moveToFirst()) {
                throw new MmsException("Bad uri: " + uri);
            }
            msgBox = c.getInt(PDU_COLUMN_MESSAGE_BOX);
            threadId = c.getLong(PDU_COLUMN_THREAD_ID);
            set = ENCODED_STRING_COLUMN_INDEX_MAP.entrySet();
            for (Entry<Integer, Integer> e : set) {
                setEncodedStringValueToHeaders(c, e.getValue(), headers, e.getKey());
            }
            set = TEXT_STRING_COLUMN_INDEX_MAP.entrySet();
            for (Entry<Integer, Integer> e : set) {
                setTextStringToHeaders(c, e.getValue(), headers, e.getKey());
            }
            set = OCTET_COLUMN_INDEX_MAP.entrySet();
            for (Entry<Integer, Integer> e : set) {
                setOctetToHeaders(c, e.getValue(), headers, e.getKey());
            }
            set = LONG_COLUMN_INDEX_MAP.entrySet();
            for (Entry<Integer, Integer> e : set) {
                setLongToHeaders(c, e.getValue(), headers, e.getKey());
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
        // Check whether 'msgId' has been assigned a valid value.
        if (msgId == -1L) {
            throw new MmsException("Error! ID of the message: -1.");
        }
        // Load address information of the MM.
        loadAddress(msgId, headers);
        int msgType = headers.getOctet(PduHeaders.MESSAGE_TYPE);
        PduBody body = new PduBody();
        // load multiparts and put them into the body of the PDU.
        if ((msgType == PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF) || (msgType == PduHeaders.MESSAGE_TYPE_SEND_REQ)) {
            PduPart[] parts = loadParts(msgId);
            if (parts != null) {
                int partsNum = parts.length;
                for (int i = 0; i < partsNum; i++) {
                    body.addPart(parts[i]);
                }
            }
        }
        switch(msgType) {
            case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
                pdu = new NotificationInd(headers);
                break;
            case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
                pdu = new DeliveryInd(headers);
                break;
            case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
                pdu = new ReadOrigInd(headers);
                break;
            case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
                pdu = new RetrieveConf(headers, body);
                break;
            case PduHeaders.MESSAGE_TYPE_SEND_REQ:
                pdu = new SendReq(headers, body);
                break;
            case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
                pdu = new AcknowledgeInd(headers);
                break;
            case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
                pdu = new NotifyRespInd(headers);
                break;
            case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
                pdu = new ReadRecInd(headers);
                break;
            case PduHeaders.MESSAGE_TYPE_SEND_CONF:
            case PduHeaders.MESSAGE_TYPE_FORWARD_REQ:
            case PduHeaders.MESSAGE_TYPE_FORWARD_CONF:
            case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ:
            case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF:
            case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ:
            case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF:
            case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ:
            case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF:
            case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ:
            case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF:
            case PduHeaders.MESSAGE_TYPE_MBOX_DESCR:
            case PduHeaders.MESSAGE_TYPE_DELETE_REQ:
            case PduHeaders.MESSAGE_TYPE_DELETE_CONF:
            case PduHeaders.MESSAGE_TYPE_CANCEL_REQ:
            case PduHeaders.MESSAGE_TYPE_CANCEL_CONF:
                throw new MmsException("Unsupported PDU type: " + Integer.toHexString(msgType));
            default:
                throw new MmsException("Unrecognized PDU type: " + Integer.toHexString(msgType));
        }
    } finally {
        synchronized (PDU_CACHE_INSTANCE) {
            if (pdu != null) {
                assert (PDU_CACHE_INSTANCE.get(uri) == null);
                // Update the cache entry with the real info
                cacheEntry = new PduCacheEntry(pdu, msgBox, threadId);
                PDU_CACHE_INSTANCE.put(uri, cacheEntry);
            }
            PDU_CACHE_INSTANCE.setUpdating(uri, false);
            // tell anybody waiting on this entry to go ahead
            PDU_CACHE_INSTANCE.notifyAll();
        }
    }
    return pdu;
}
Also used : PduCacheEntry(com.google.android.mms.util_alt.PduCacheEntry) Cursor(android.database.Cursor) PduCacheEntry(com.google.android.mms.util_alt.PduCacheEntry) Entry(java.util.Map.Entry) MmsException(com.google.android.mms.MmsException)

Example 17 with MmsException

use of com.google.android.mms.MmsException in project qksms by moezbhatti.

the class PduPersister method move.

/**
 * Move a PDU object from one location to another.
 *
 * @param from Specify the PDU object to be moved.
 * @param to The destination location, should be one of the following:
 *        "content://mms/inbox", "content://mms/sent",
 *        "content://mms/drafts", "content://mms/outbox",
 *        "content://mms/trash".
 * @return New Uri of the moved PDU.
 * @throws MmsException Error occurred while moving the message.
 */
public Uri move(Uri from, Uri to) throws MmsException {
    // Check whether the 'msgId' has been assigned a valid value.
    long msgId = ContentUris.parseId(from);
    if (msgId == -1L) {
        throw new MmsException("Error! ID of the message: -1.");
    }
    // Get corresponding int value of destination box.
    Integer msgBox = MESSAGE_BOX_MAP.get(to);
    if (msgBox == null) {
        throw new MmsException("Bad destination, must be one of " + "content://mms/inbox, content://mms/sent, " + "content://mms/drafts, content://mms/outbox, " + "content://mms/temp.");
    }
    ContentValues values = new ContentValues(1);
    values.put("msg_box", msgBox);
    SqliteWrapper.update(mContext, mContentResolver, from, values, null, null);
    return ContentUris.withAppendedId(to, msgId);
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException)

Example 18 with MmsException

use of com.google.android.mms.MmsException in project qksms by moezbhatti.

the class MessageUtils method isDrmRingtoneWithRights.

/**
 * Returns true if any part is drm'd audio with ringtone rights.
 *
 * @param context
 * @param msgId
 * @return true if one of the parts is drm'd audio with rights to save as a ringtone.
 */
public static boolean isDrmRingtoneWithRights(Context context, long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(context, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "isDrmRingtoneWithRights 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)) {
            String mimeType = QKSMSApp.getApplication().getDrmManagerClient().getOriginalMimeType(part.getDataUri());
            if (ContentType.isAudioType(mimeType) && DrmUtils.haveRightsForAction(part.getDataUri(), DrmStore.Action.RINGTONE)) {
                return true;
            }
        }
    }
    return false;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu_alt.PduBody) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 19 with MmsException

use of com.google.android.mms.MmsException in project qksms by moezbhatti.

the class MessageUtils method haveSomethingToCopyToSDCard.

/**
 * Looks to see if there are any valid parts of the attachment that can be copied to a SD card.
 *
 * @param context
 * @param msgId
 */
public static boolean haveSomethingToCopyToSDCard(Context context, long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(context, 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.v(TAG, "[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_alt.PduBody) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 20 with MmsException

use of com.google.android.mms.MmsException in project qksms by moezbhatti.

the class PduPersister method persistPart.

public Uri persistPart(PduPart part, long msgId, HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {
    Uri uri = Uri.parse("content://mms/" + msgId + "/part");
    ContentValues values = new ContentValues(8);
    int charset = part.getCharset();
    if (charset != 0) {
        values.put("chset", charset);
    }
    String contentType = getPartContentType(part);
    if (contentType != null) {
        // Change it to "image/jpeg"
        if (ContentType.IMAGE_JPG.equals(contentType)) {
            contentType = ContentType.IMAGE_JPEG;
        }
        values.put("ct", contentType);
        // To ensure the SMIL part is always the first part.
        if (ContentType.APP_SMIL.equals(contentType)) {
            values.put("seq", -1);
        }
    } else {
        throw new MmsException("MIME type of the part must be set.");
    }
    if (part.getFilename() != null) {
        String fileName = new String(part.getFilename());
        values.put("fn", fileName);
    }
    if (part.getName() != null) {
        String name = new String(part.getName());
        values.put("name", name);
    }
    Object value = null;
    if (part.getContentDisposition() != null) {
        value = toIsoString(part.getContentDisposition());
        values.put("cd", (String) value);
    }
    if (part.getContentId() != null) {
        value = toIsoString(part.getContentId());
        values.put("cid", (String) value);
    }
    if (part.getContentLocation() != null) {
        value = toIsoString(part.getContentLocation());
        values.put("cl", (String) value);
    }
    Uri res = SqliteWrapper.insert(mContext, mContentResolver, uri, values);
    if (res == null) {
        throw new MmsException("Failed to persist part, return null.");
    }
    persistData(part, res, contentType, preOpenedFiles);
    // After successfully store the data, we should update
    // the dataUri of the part.
    part.setDataUri(res);
    return res;
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException) Uri(android.net.Uri)

Aggregations

MmsException (com.google.android.mms.MmsException)39 Uri (android.net.Uri)15 ContentValues (android.content.ContentValues)14 Cursor (android.database.Cursor)10 IOException (java.io.IOException)10 PduBody (com.google.android.mms.pdu_alt.PduBody)6 PduPart (com.google.android.mms.pdu_alt.PduPart)6 PduPersister (com.google.android.mms.pdu_alt.PduPersister)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Intent (android.content.Intent)5 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)5 InputStream (java.io.InputStream)4 ContentResolver (android.content.ContentResolver)3 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)3 EncodedStringValue (com.google.android.mms.pdu.EncodedStringValue)3 SendReq (com.google.android.mms.pdu_alt.SendReq)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Resources (android.content.res.Resources)2