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);
}
}
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
Aggregations