use of com.google.android.mms.MmsException in project qksms by moezbhatti.
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 = Utils.getMyPhoneNumber(mContext);
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, Uri.parse("content://mms/sent"));
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) {
Log.e(TAG, "Unexpected RuntimeException.", e);
} finally {
if (mTransactionState.getState() != TransactionState.SUCCESS) {
mTransactionState.setState(TransactionState.FAILED);
mTransactionState.setContentUri(mReadReportURI);
}
notifyObservers();
}
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
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);
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
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;
if (isDuplicateMessage(mContext, retrieveConf)) {
// Mark this transaction as failed to prevent duplicate
// notification to user.
mTransactionState.setState(TransactionState.FAILED);
mTransactionState.setContentUri(mUri);
} else {
boolean group;
try {
group = com.moez.QKSMS.mmssms.Transaction.settings.getGroup();
} catch (Exception e) {
group = PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("pref_key_compose_group", true);
}
// Store M-Retrieve.conf into Inbox
PduPersister persister = PduPersister.getPduPersister(mContext);
msgUri = persister.persist(retrieveConf, Uri.parse("content://mms/inbox"), true, group, 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);
// 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.");
} else {
mContext.sendBroadcast(new Intent(com.moez.QKSMS.mmssms.Transaction.NOTIFY_OF_MMS));
}
notifyObservers();
}
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
the class MmsMessageSender method sendReadRec.
public static void sendReadRec(Context context, String to, String messageId, int status) {
EncodedStringValue[] sender = new EncodedStringValue[1];
sender[0] = new EncodedStringValue(to);
try {
final ReadRecInd readRec = new ReadRecInd(new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()), messageId.getBytes(), PduHeaders.CURRENT_MMS_VERSION, status, sender);
readRec.setDate(System.currentTimeMillis() / 1000);
boolean group;
try {
group = com.moez.QKSMS.mmssms.Transaction.settings.getGroup();
} catch (Exception e) {
group = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pref_key_compose_group", true);
}
PduPersister.getPduPersister(context).persist(readRec, Uri.parse("content://mms/outbox"), true, group, null);
Intent service = new Intent(TransactionService.HANDLE_PENDING_TRANSACTIONS_ACTION, null, context, TransactionService.class);
context.startService(service);
} catch (InvalidHeaderValueException e) {
Log.e(TAG, "Invalide header value", e);
} catch (MmsException e) {
Log.e(TAG, "Persist message failed", e);
}
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
the class PduPersister method loadParts.
private PduPart[] loadParts(long msgId) throws MmsException {
Cursor c = SqliteWrapper.query(mContext, mContentResolver, Uri.parse("content://mms/" + msgId + "/part"), PART_PROJECTION, null, null, null);
PduPart[] parts = null;
try {
if ((c == null) || (c.getCount() == 0)) {
if (LOCAL_LOGV)
Log.v(TAG, "loadParts(" + msgId + "): no part to load.");
return null;
}
int partCount = c.getCount();
int partIdx = 0;
parts = new PduPart[partCount];
while (c.moveToNext()) {
PduPart part = new PduPart();
Integer charset = getIntegerFromPartColumn(c, PART_COLUMN_CHARSET);
if (charset != null) {
part.setCharset(charset);
}
byte[] contentDisposition = getByteArrayFromPartColumn(c, PART_COLUMN_CONTENT_DISPOSITION);
if (contentDisposition != null) {
part.setContentDisposition(contentDisposition);
}
byte[] contentId = getByteArrayFromPartColumn(c, PART_COLUMN_CONTENT_ID);
if (contentId != null) {
part.setContentId(contentId);
}
byte[] contentLocation = getByteArrayFromPartColumn(c, PART_COLUMN_CONTENT_LOCATION);
if (contentLocation != null) {
part.setContentLocation(contentLocation);
}
byte[] contentType = getByteArrayFromPartColumn(c, PART_COLUMN_CONTENT_TYPE);
if (contentType != null) {
part.setContentType(contentType);
} else {
throw new MmsException("Content-Type must be set.");
}
byte[] fileName = getByteArrayFromPartColumn(c, PART_COLUMN_FILENAME);
if (fileName != null) {
part.setFilename(fileName);
}
byte[] name = getByteArrayFromPartColumn(c, PART_COLUMN_NAME);
if (name != null) {
part.setName(name);
}
// Construct a Uri for this part.
long partId = c.getLong(PART_COLUMN_ID);
Uri partURI = Uri.parse("content://mms/part/" + partId);
part.setDataUri(partURI);
// For images/audio/video, we won't keep their data in Part
// because their renderer accept Uri as source.
String type = toIsoString(contentType);
if (!ContentType.isImageType(type) && !ContentType.isAudioType(type) && !ContentType.isVideoType(type)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
// faster.
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type) || ContentType.TEXT_HTML.equals(type)) {
String text = c.getString(PART_COLUMN_TEXT);
byte[] blob = new EncodedStringValue(text != null ? text : "").getTextString();
baos.write(blob, 0, blob.length);
} else {
try {
is = mContentResolver.openInputStream(partURI);
byte[] buffer = new byte[256];
int len = is.read(buffer);
while (len >= 0) {
baos.write(buffer, 0, len);
len = is.read(buffer);
}
} catch (IOException e) {
Log.e(TAG, "Failed to load part data", e);
c.close();
throw new MmsException(e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
Log.e(TAG, "Failed to close stream", e);
}
// Ignore
}
}
}
part.setData(baos.toByteArray());
}
parts[partIdx++] = part;
}
} finally {
if (c != null) {
c.close();
}
}
return parts;
}
Aggregations