Support for multiple APN settings on the same provider

This commit is contained in:
Ruben Pollan 2014-01-14 02:02:52 -10:00 committed by Moxie Marlinspike
parent addea8d340
commit 5785860631
4 changed files with 70 additions and 47 deletions

View File

@ -22,7 +22,8 @@ public class ApnDefaults {
put("310260", new MmsConnectionParameters("http://mms.msg.eng.t-mobile.com/mms/wapenc", null, null)); put("310260", new MmsConnectionParameters("http://mms.msg.eng.t-mobile.com/mms/wapenc", null, null));
//AT&T - Testd //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 //Verizon - Untested
put("310004", new MmsConnectionParameters("http://mms.vtext.com/servlets/mms", null, null)); 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("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("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("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("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("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")); put("31043", new MmsConnectionParameters("http://mms.metropcs.net:3128/mmsc", "proxy.metropcs.net", "3128"));

View File

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

View File

@ -34,7 +34,7 @@ import ws.com.google.android.mms.pdu.RetrieveConf;
public class MmsDownloadHelper extends MmsCommunication { 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 throws IOException
{ {
AndroidHttpClient client = null; AndroidHttpClient client = null;
@ -78,13 +78,17 @@ public class MmsDownloadHelper extends MmsCommunication {
throws IOException, ApnUnavailableException throws IOException, ApnUnavailableException
{ {
MmsConnectionParameters connectionParameters = getMmsConnectionParameters(context, apn, proxyIfPossible); MmsConnectionParameters connectionParameters = getMmsConnectionParameters(context, apn, proxyIfPossible);
byte[] pdu = null;
checkRouteToHost(context, connectionParameters, url, usingMmsRadio); for (MmsConnectionParameters.Apn param : connectionParameters.get()) {
if (checkRouteToHost(context, param, param.getMmsc(), usingMmsRadio)) {
byte[] pdu = makeRequest(context, connectionParameters, url); pdu = makeRequest(context, param, url);
if (pdu != null) break;
}
}
if (pdu == null) { 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(); RetrieveConf retrieved = (RetrieveConf)new PduParser(pdu).parse();

View File

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