use of com.google.android.mms.pdu_alt.PduParser in project qksms by moezbhatti.
the class DownloadRequest method persist.
public static Uri persist(Context context, byte[] response, MmsConfig.Overridden mmsConfig, String locationUrl, int subId, String creator) {
// Let any mms apps running as secondary user know that a new mms has been downloaded.
notifyOfDownload(context);
Timber.d("DownloadRequest.persistIfRequired");
if (response == null || response.length < 1) {
Timber.e("DownloadRequest.persistIfRequired: empty response");
// Update the retrieve status of the NotificationInd
final ContentValues values = new ContentValues(1);
values.put(Telephony.Mms.RETRIEVE_STATUS, PduHeaders.RETRIEVE_STATUS_ERROR_END);
SqliteWrapper.update(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, values, LOCATION_SELECTION, new String[] { Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), locationUrl });
return null;
}
final long identity = Binder.clearCallingIdentity();
try {
final GenericPdu pdu = (new PduParser(response, mmsConfig.getSupportMmsContentDisposition())).parse();
if (pdu == null || !(pdu instanceof RetrieveConf)) {
Timber.e("DownloadRequest.persistIfRequired: invalid parsed PDU");
// Update the error type of the NotificationInd
setErrorType(context, locationUrl, Telephony.MmsSms.ERR_TYPE_MMS_PROTO_PERMANENT);
return null;
}
final RetrieveConf retrieveConf = (RetrieveConf) pdu;
final int status = retrieveConf.getRetrieveStatus();
// if (status != PduHeaders.RETRIEVE_STATUS_OK) {
// Timber.e("DownloadRequest.persistIfRequired: retrieve failed "
// + status);
// // Update the retrieve status of the NotificationInd
// final ContentValues values = new ContentValues(1);
// values.put(Telephony.Mms.RETRIEVE_STATUS, status);
// SqliteWrapper.update(
// context,
// context.getContentResolver(),
// Telephony.Mms.CONTENT_URI,
// values,
// LOCATION_SELECTION,
// new String[]{
// Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND),
// mLocationUrl
// });
// return null;
// }
// Store the downloaded message
final PduPersister persister = PduPersister.getPduPersister(context);
final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, PduPersister.DUMMY_THREAD_ID, true, true, null);
if (messageUri == null) {
Timber.e("DownloadRequest.persistIfRequired: can not persist message");
return null;
}
// Update some of the properties of the message
final ContentValues values = new ContentValues();
values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L);
try {
values.put(Telephony.Mms.DATE_SENT, retrieveConf.getDate());
} catch (Exception ignored) {
}
values.put(Telephony.Mms.READ, 0);
values.put(Telephony.Mms.SEEN, 0);
if (!TextUtils.isEmpty(creator)) {
values.put(Telephony.Mms.CREATOR, creator);
}
if (SubscriptionIdChecker.getInstance(context).canUseSubscriptionId()) {
values.put(Telephony.Mms.SUBSCRIPTION_ID, subId);
}
try {
context.getContentResolver().update(messageUri, values, null, null);
} catch (SQLiteException e) {
// in advance that it will fail, and we have to just try again
if (values.containsKey(Telephony.Mms.SUBSCRIPTION_ID)) {
values.remove(Telephony.Mms.SUBSCRIPTION_ID);
context.getContentResolver().update(messageUri, values, null, null);
} else {
throw e;
}
}
// Delete the corresponding NotificationInd
SqliteWrapper.delete(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, LOCATION_SELECTION, new String[] { Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), locationUrl });
return messageUri;
} catch (MmsException e) {
Timber.e(e, "DownloadRequest.persistIfRequired: can not persist message");
} catch (SQLiteException e) {
Timber.e(e, "DownloadRequest.persistIfRequired: can not update message");
} catch (RuntimeException e) {
Timber.e(e, "DownloadRequest.persistIfRequired: can not parse response");
} finally {
Binder.restoreCallingIdentity(identity);
}
return null;
}
use of com.google.android.mms.pdu_alt.PduParser in project Signal-Android by WhisperSystems.
the class IncomingLegacyMmsConnection method retrieve.
public RetrieveConf retrieve(Apn contentApn, byte[] transactionId, boolean usingMmsRadio, boolean useProxyIfAvailable) throws IOException, ApnUnavailableException {
byte[] pdu = null;
final boolean useProxy = useProxyIfAvailable && contentApn.hasProxy();
final String targetHost = useProxy ? contentApn.getProxy() : Uri.parse(contentApn.getMmsc()).getHost();
if (checkRouteToHost(context, targetHost, usingMmsRadio)) {
Log.i(TAG, "got successful route to host " + targetHost);
pdu = execute(constructRequest(contentApn, useProxy));
}
if (pdu == null) {
throw new IOException("Connection manager could not obtain route to host.");
}
RetrieveConf retrieved = (RetrieveConf) new PduParser(pdu).parse();
if (retrieved == null) {
Log.w(TAG, "Couldn't parse PDU, byte response: " + Arrays.toString(pdu));
Log.w(TAG, "Couldn't parse PDU, ASCII: " + new String(pdu));
throw new IOException("Bad retrieved PDU");
}
sendRetrievedAcknowledgement(transactionId, usingMmsRadio, useProxy);
return retrieved;
}
use of com.google.android.mms.pdu_alt.PduParser in project Signal-Android by signalapp.
the class MmsReceiveJob method onRun.
@Override
public void onRun() {
if (data == null) {
Log.w(TAG, "Received NULL pdu, ignoring...");
return;
}
PduParser parser = new PduParser(data);
GenericPdu pdu = null;
try {
pdu = parser.parse();
} catch (RuntimeException e) {
Log.w(TAG, e);
}
if (isNotification(pdu) && !isBlocked(pdu)) {
MessageDatabase database = SignalDatabase.mms();
Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd) pdu, subscriptionId);
Log.i(TAG, "Inserted received MMS notification...");
ApplicationDependencies.getJobManager().add(new MmsDownloadJob(messageAndThreadId.first(), messageAndThreadId.second(), true));
} else if (isNotification(pdu)) {
Log.w(TAG, "*** Received blocked MMS, ignoring...");
}
}
use of com.google.android.mms.pdu_alt.PduParser in project cadpage-cadpage by cadpage.
the class MMSParser method parseMsg.
private static void parseMsg(String data) {
byte[] byteData = cvtHexString(data);
GenericPdu pdu;
try {
PduParser parser = new PduParser(byteData);
pdu = parser.parse();
} catch (Exception ex) {
ex.printStackTrace();
return;
}
if (null == pdu) {
System.err.println("Invalid PUSH data");
return;
}
System.out.println("PDU:" + pdu.getClass().getName());
SmsMmsMessage message = MmsUtil.getMessage(pdu);
if (message == null) {
System.err.println("Empty MMS message");
return;
}
System.out.println("Parse succeeded");
System.out.println("Subject:" + message.getSubject());
System.out.println("ContentLoc:" + message.getContentLoc());
System.out.println("MmsMsgId:" + message.getMmsMsgId());
}
Aggregations