Skip to content
Commits on Source (4)
......@@ -23,17 +23,27 @@ import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.util.Log;
import com.google.android.mms.InvalidHeaderValueException;
import com.google.android.mms.pdu_alt.NotifyRespInd;
import com.google.android.mms.pdu_alt.PduComposer;
import com.google.android.mms.pdu_alt.PduHeaders;
import com.google.android.mms.pdu_alt.PduParser;
import com.google.android.mms.pdu_alt.RetrieveConf;
import org.smssecure.smssecure.providers.MmsBodyProvider;
import org.smssecure.smssecure.transport.UndeliverableMessageException;
import org.smssecure.smssecure.util.Util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeoutException;
public class IncomingLollipopMmsConnection extends LollipopMmsConnection implements IncomingMmsConnection {
......@@ -65,7 +75,12 @@ public class IncomingLollipopMmsConnection extends LollipopMmsConnection impleme
try {
MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
Log.w(TAG, "downloading multimedia from " + contentLocation + " to " + pointer.getUri());
final String transactionIdString = Util.toIsoString(transactionId);
Log.w(TAG, String.format(Locale.ENGLISH, "Downloading subscriptionId=%s multimedia from '%s' [transactionId='%s'] to '%s'",
subscriptionId,
contentLocation,
transactionIdString,
pointer.getUri()));
SmsManager smsManager;
......@@ -75,10 +90,29 @@ public class IncomingLollipopMmsConnection extends LollipopMmsConnection impleme
smsManager = SmsManager.getDefault();
}
final Bundle configOverrides = smsManager.getCarrierConfigValues();
if (configOverrides.getBoolean(SmsManager.MMS_CONFIG_APPEND_TRANSACTION_ID)) {
if (!contentLocation.contains(transactionIdString)) {
Log.w(TAG, "Appending transactionId to contentLocation at the direction of CarrierConfigValues. New location: " + contentLocation);
contentLocation += transactionIdString;
} else {
Log.w(TAG, "Skipping 'append transaction id' as contentLocation already contains it");
}
}
if (TextUtils.isEmpty(configOverrides.getString(SmsManager.MMS_CONFIG_USER_AGENT))) {
configOverrides.remove(SmsManager.MMS_CONFIG_USER_AGENT);
}
if (TextUtils.isEmpty(configOverrides.getString(SmsManager.MMS_CONFIG_UA_PROF_URL))) {
configOverrides.remove(SmsManager.MMS_CONFIG_UA_PROF_URL);
}
smsManager.downloadMultimediaMessage(getContext(),
contentLocation,
pointer.getUri(),
null,
configOverrides,
getPendingIntent());
waitForResult();
......@@ -89,7 +123,12 @@ public class IncomingLollipopMmsConnection extends LollipopMmsConnection impleme
Log.w(TAG, baos.size() + "-byte response: ");// + Hex.dump(baos.toByteArray()));
return (RetrieveConf) new PduParser(baos.toByteArray()).parse();
RetrieveConf retrieved = (RetrieveConf) new PduParser(baos.toByteArray()).parse();
if (retrieved == null) return null;
sendRetrievedAcknowledgement(transactionId, retrieved.getMmsVersion(), subscriptionId);
return retrieved;
} catch (IOException | TimeoutException e) {
Log.w(TAG, e);
throw new MmsException(e);
......@@ -97,4 +136,15 @@ public class IncomingLollipopMmsConnection extends LollipopMmsConnection impleme
endTransaction();
}
}
private void sendRetrievedAcknowledgement(byte[] transactionId, int mmsVersion, int subscriptionId) {
try {
NotifyRespInd retrieveResponse = new NotifyRespInd(mmsVersion, transactionId, PduHeaders.STATUS_RETRIEVED);
new OutgoingLollipopMmsConnection(getContext()).send(new PduComposer(getContext(), retrieveResponse).make(), subscriptionId);
} catch (UndeliverableMessageException e) {
Log.w(TAG, e);
} catch (InvalidHeaderValueException e) {
Log.w(TAG, e);
}
}
}