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