use of ws.com.google.android.mms.pdu.PduParser in project Signal-Android by WhisperSystems.
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)) {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd) pdu, subscriptionId);
Log.w(TAG, "Inserted received MMS notification...");
ApplicationContext.getInstance(context).getJobManager().add(new MmsDownloadJob(context, messageAndThreadId.first, messageAndThreadId.second, true));
} else if (isNotification(pdu)) {
Log.w(TAG, "*** Received blocked MMS, ignoring...");
}
}
use of ws.com.google.android.mms.pdu.PduParser in project Signal-Android by WhisperSystems.
the class IncomingLollipopMmsConnection method retrieve.
@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized RetrieveConf retrieve(@NonNull String contentLocation, byte[] transactionId, int subscriptionId) throws MmsException {
beginTransaction();
try {
MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
Log.w(TAG, "downloading multimedia from " + contentLocation + " to " + pointer.getUri());
SmsManager smsManager;
if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
} else {
smsManager = SmsManager.getDefault();
}
smsManager.downloadMultimediaMessage(getContext(), contentLocation, pointer.getUri(), null, getPendingIntent());
waitForResult();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Util.copy(pointer.getInputStream(), baos);
pointer.close();
Log.w(TAG, baos.size() + "-byte response: " + Hex.dump(baos.toByteArray()));
return (RetrieveConf) new PduParser(baos.toByteArray()).parse();
} catch (IOException | TimeoutException e) {
Log.w(TAG, e);
throw new MmsException(e);
} finally {
endTransaction();
}
}
use of ws.com.google.android.mms.pdu.PduParser in project Signal-Android by WhisperSystems.
the class OutgoingLollipopMmsConnection method send.
@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId) throws UndeliverableMessageException {
beginTransaction();
try {
MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
Util.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());
SmsManager smsManager;
if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
} else {
smsManager = SmsManager.getDefault();
}
smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, null, getPendingIntent());
waitForResult();
Log.w(TAG, "MMS broadcast received and processed.");
pointer.close();
if (response == null) {
throw new UndeliverableMessageException("Null response.");
}
return (SendConf) new PduParser(response).parse();
} catch (IOException | TimeoutException e) {
throw new UndeliverableMessageException(e);
} finally {
endTransaction();
}
}
use of ws.com.google.android.mms.pdu.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.w(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;
}
Aggregations