Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple APN settings on the same provider #552

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/org/thoughtcrime/securesms/mms/ApnDefaults.java
Expand Up @@ -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));
Expand Down Expand Up @@ -256,7 +257,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"));
Expand Down
77 changes: 48 additions & 29 deletions src/org/thoughtcrime/securesms/mms/MmsCommunication.java
Expand Up @@ -39,6 +39,8 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;

public class MmsCommunication {

Expand Down Expand Up @@ -122,17 +124,17 @@ protected static MmsConnectionParameters getMmsConnectionParameters(Context cont
}
}

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);
Expand All @@ -142,7 +144,7 @@ private static void checkRouteToHost(Context context, String host, boolean using
throw new IOException("RFC1918 address in non-MMS radio situation!");
}

return;
return true;
}

Log.w("MmsCommunication", "Checking route to address: " + host + " , " + inetAddress.getHostAddress());
Expand All @@ -153,12 +155,12 @@ private static void checkRouteToHost(Context context, String host, boolean using
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");
Expand Down Expand Up @@ -188,36 +190,53 @@ protected static byte[] parseResponse(HttpEntity entity) throws IOException {
}

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;
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java
Expand Up @@ -34,7 +34,7 @@

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;
Expand Down Expand Up @@ -78,13 +78,17 @@ public static RetrieveConf retrieveMms(Context context, String url, String apn,
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();
Expand Down
16 changes: 8 additions & 8 deletions src/org/thoughtcrime/securesms/mms/MmsSendHelper.java
Expand Up @@ -37,7 +37,7 @@

public class MmsSendHelper extends MmsCommunication {

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;
Expand Down Expand Up @@ -88,11 +88,6 @@ public static SendConf sendMms(Context context, byte[] mms, String apn,
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();
}

Expand All @@ -103,8 +98,13 @@ private static byte[] sendBytes(Context context, byte[] mms, String apn,
Log.w("MmsSender", "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("MmsSender", aue);
throw new IOException("Failed to get MMSC information...");
Expand Down