Support for multiple APN settings on the same provider

pull/1/head
Ruben Pollan 11 years ago committed by Moxie Marlinspike
parent addea8d340
commit 5785860631

@ -22,7 +22,8 @@ public class ApnDefaults {
put("310260", new MmsConnectionParameters("http://mms.msg.eng.t-mobile.com/mms/wapenc", null, null));
//AT&T - Testd
put("310410", new MmsConnectionParameters("http://mmsc.mobile.att.net", "proxy.mobile.att.net", "80"));
put("310410", (new MmsConnectionParameters("http://mmsc.cingular.com", "wireless.cingular.com", "80"))
.add("http://mmsc.mobile.att.net", "proxy.mobile.att.net", "80"));
//Verizon - Untested
put("310004", new MmsConnectionParameters("http://mms.vtext.com/servlets/mms", null, null));
@ -257,7 +258,6 @@ public class ApnDefaults {
put("31039", new MmsConnectionParameters("http://mms.metropcs.net:3128/mmsc", "proxy.metropcs.net", "3128"));
put("31040", new MmsConnectionParameters("http://mms.sprintpcs.com", "68.28.31.7", "80"));
put("31041", new MmsConnectionParameters("http://mms.metropcs.net:3128/mmsc", "proxy.metropcs.net", "3128"));
put("310410", new MmsConnectionParameters("http://mmsc.mobile.att.net", "proxy.mobile.att.net", "80"));
put("31042", new MmsConnectionParameters("http://mms.metropcs.net:3128/mmsc", "proxy.metropcs.net", "3128"));
put("310420", new MmsConnectionParameters("http://mms.gocbw.com:8088/mms", "216.68.79.202", "80"));
put("31043", new MmsConnectionParameters("http://mms.metropcs.net:3128/mmsc", "proxy.metropcs.net", "3128"));

@ -39,6 +39,8 @@ import org.whispersystems.textsecure.util.Util;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
public class MmsCommunication {
@ -122,17 +124,17 @@ public class MmsCommunication {
}
}
protected static void checkRouteToHost(Context context, MmsConnectionParameters parameters,
protected static boolean checkRouteToHost(Context context, MmsConnectionParameters.Apn parameters,
String url, boolean usingMmsRadio)
throws IOException
{
if (parameters == null || !parameters.hasProxy())
checkRouteToHost(context, Uri.parse(url).getHost(), usingMmsRadio);
return checkRouteToHost(context, Uri.parse(url).getHost(), usingMmsRadio);
else
checkRouteToHost(context, parameters.getProxy(), usingMmsRadio);
return checkRouteToHost(context, parameters.getProxy(), usingMmsRadio);
}
private static void checkRouteToHost(Context context, String host, boolean usingMmsRadio)
private static boolean checkRouteToHost(Context context, String host, boolean usingMmsRadio)
throws IOException
{
InetAddress inetAddress = InetAddress.getByName(host);
@ -142,7 +144,7 @@ public class MmsCommunication {
throw new IOException("RFC1918 address in non-MMS radio situation!");
}
return;
return true;
}
Log.w("MmsCommunication", "Checking route to address: " + host + " , " + inetAddress.getHostAddress());
@ -153,12 +155,12 @@ public class MmsCommunication {
int ipAddress = Conversions.byteArrayToIntLittleEndian(ipAddressBytes, 0);
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (!manager.requestRouteToHost(MmsRadio.TYPE_MOBILE_MMS, ipAddress))
throw new IOException("Connection manager could not obtain route to host.");
return manager.requestRouteToHost(MmsRadio.TYPE_MOBILE_MMS, ipAddress);
}
return true;
}
protected static AndroidHttpClient constructHttpClient(Context context, MmsConnectionParameters mmsConfig) {
protected static AndroidHttpClient constructHttpClient(Context context, MmsConnectionParameters.Apn mmsConfig) {
AndroidHttpClient client = AndroidHttpClient.newInstance("Android-Mms/2.0", context);
HttpParams params = client.getParams();
HttpProtocolParams.setContentCharset(params, "UTF-8");
@ -188,36 +190,53 @@ public class MmsCommunication {
}
protected static class MmsConnectionParameters {
private final String mmsc;
private final String proxy;
private final String port;
public class Apn {
private final String mmsc;
private final String proxy;
private final String port;
public Apn(String mmsc, String proxy, String port) {
this.mmsc = mmsc;
this.proxy = proxy;
this.port = port;
}
public MmsConnectionParameters(String mmsc, String proxy, String port) {
this.mmsc = mmsc;
this.proxy = proxy;
this.port = port;
}
public boolean hasProxy() {
return !Util.isEmpty(proxy);
}
public boolean hasProxy() {
return !Util.isEmpty(proxy);
}
public String getMmsc() {
return mmsc;
}
public String getProxy() {
if (!hasProxy())
return null;
public String getMmsc() {
return mmsc;
return proxy;
}
public int getPort() {
if (Util.isEmpty(port))
return 80;
return Integer.parseInt(port);
}
}
public String getProxy() {
if (!hasProxy())
return null;
private List<Apn> apn = new ArrayList<Apn>();
return proxy;
public MmsConnectionParameters(String mmsc, String proxy, String port) {
apn.add(new Apn(mmsc, proxy, port));
}
public int getPort() {
if (Util.isEmpty(port))
return 80;
public MmsConnectionParameters add(String mmsc, String proxy, String port) {
apn.add(new Apn(mmsc, proxy, port));
return this;
}
return Integer.parseInt(port);
public List<Apn> get() {
return apn;
}
}

@ -34,7 +34,7 @@ import ws.com.google.android.mms.pdu.RetrieveConf;
public class MmsDownloadHelper extends MmsCommunication {
private static byte[] makeRequest(Context context, MmsConnectionParameters connectionParameters, String url)
private static byte[] makeRequest(Context context, MmsConnectionParameters.Apn connectionParameters, String url)
throws IOException
{
AndroidHttpClient client = null;
@ -78,13 +78,17 @@ public class MmsDownloadHelper extends MmsCommunication {
throws IOException, ApnUnavailableException
{
MmsConnectionParameters connectionParameters = getMmsConnectionParameters(context, apn, proxyIfPossible);
byte[] pdu = null;
checkRouteToHost(context, connectionParameters, url, usingMmsRadio);
byte[] pdu = makeRequest(context, connectionParameters, url);
for (MmsConnectionParameters.Apn param : connectionParameters.get()) {
if (checkRouteToHost(context, param, param.getMmsc(), usingMmsRadio)) {
pdu = makeRequest(context, param, url);
if (pdu != null) break;
}
}
if (pdu == null) {
throw new IOException("Retrieved null PDU!");
throw new IOException("Connection manager could not obtain route to host.");
}
RetrieveConf retrieved = (RetrieveConf)new PduParser(pdu).parse();

@ -39,7 +39,7 @@ import ws.com.google.android.mms.pdu.SendConf;
public class MmsSendHelper extends MmsCommunication {
private final static String TAG = MmsSendHelper.class.getSimpleName();
private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms)
private static byte[] makePost(Context context, MmsConnectionParameters.Apn parameters, byte[] mms)
throws IOException
{
AndroidHttpClient client = null;
@ -90,11 +90,6 @@ public class MmsSendHelper extends MmsCommunication {
throws IOException
{
byte[] response = sendBytes(context, mms, apn, usingMmsRadio, useProxyIfAvailable);
if (response == null) {
throw new IOException("Got null response!");
}
return (SendConf) new PduParser(response).parse();
}
@ -105,8 +100,13 @@ public class MmsSendHelper extends MmsCommunication {
Log.w(TAG, "Sending MMS of length: " + mms.length);
try {
MmsConnectionParameters parameters = getMmsConnectionParameters(context, apn, useProxyIfAvailable);
checkRouteToHost(context, parameters, parameters.getMmsc(), usingMmsRadio);
return makePost(context, parameters, mms);
for (MmsConnectionParameters.Apn param : parameters.get()) {
if (checkRouteToHost(context, param, param.getMmsc(), usingMmsRadio)) {
byte[] response = makePost(context, param, mms);
if (response != null) return response;
}
}
throw new IOException("Connection manager could not obtain route to host.");
} catch (ApnUnavailableException aue) {
Log.w(TAG, aue);
throw new IOException("Failed to get MMSC information...");

Loading…
Cancel
Save