|
|
|
@ -20,17 +20,15 @@ import android.content.Context;
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import org.whispersystems.textsecure.util.Util;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import ws.com.google.android.mms.pdu.PduParser;
|
|
|
|
|
import ws.com.google.android.mms.pdu.SendConf;
|
|
|
|
@ -45,40 +43,56 @@ public class MmsSendHelper extends MmsCommunication {
|
|
|
|
|
|
|
|
|
|
HttpURLConnection client = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
client = constructHttpClient(url, proxy, proxyPort);
|
|
|
|
|
client.setFixedLengthStreamingMode(mms.length);
|
|
|
|
|
client.setDoInput(true);
|
|
|
|
|
client.setDoOutput(true);
|
|
|
|
|
client.setRequestMethod("POST");
|
|
|
|
|
client.setRequestProperty("Content-Type", "application/vnd.wap.mms-message");
|
|
|
|
|
client.setRequestProperty("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
|
|
|
|
client.setRequestProperty("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "Connecting to " + url);
|
|
|
|
|
client.connect();
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "Writing mms payload, " + mms.length + " bytes");
|
|
|
|
|
OutputStream out = client.getOutputStream();
|
|
|
|
|
out.write(mms);
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "Payload sent");
|
|
|
|
|
|
|
|
|
|
final InputStream is = client.getInputStream();
|
|
|
|
|
final int responseCode = client.getResponseCode();
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage());
|
|
|
|
|
|
|
|
|
|
if (responseCode != 200) {
|
|
|
|
|
throw new IOException("non-200 response");
|
|
|
|
|
int redirects = MAX_REDIRECTS;
|
|
|
|
|
final Set<String> previousUrls = new HashSet<String>();
|
|
|
|
|
String currentUrl = url;
|
|
|
|
|
while (redirects-- > 0) {
|
|
|
|
|
if (previousUrls.contains(currentUrl)) {
|
|
|
|
|
throw new IOException("redirect loop detected");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
client = constructHttpClient(currentUrl, proxy, proxyPort);
|
|
|
|
|
client.setFixedLengthStreamingMode(mms.length);
|
|
|
|
|
client.setDoInput(true);
|
|
|
|
|
client.setDoOutput(true);
|
|
|
|
|
client.setRequestMethod("POST");
|
|
|
|
|
client.setRequestProperty("Content-Type", "application/vnd.wap.mms-message");
|
|
|
|
|
client.setRequestProperty("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
|
|
|
|
client.setRequestProperty("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "connecting to " + currentUrl);
|
|
|
|
|
client.connect();
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "* writing mms payload, " + mms.length + " bytes");
|
|
|
|
|
OutputStream out = client.getOutputStream();
|
|
|
|
|
out.write(mms);
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
Log.w(TAG, "* payload sent");
|
|
|
|
|
|
|
|
|
|
int responseCode = client.getResponseCode();
|
|
|
|
|
Log.w(TAG, "* response code: " + responseCode + "/" + client.getResponseMessage());
|
|
|
|
|
|
|
|
|
|
if (responseCode == 301 || responseCode == 302) {
|
|
|
|
|
final String redirectUrl = client.getHeaderField("Location");
|
|
|
|
|
Log.w(TAG, "* Location: " + redirectUrl);
|
|
|
|
|
if (TextUtils.isEmpty(redirectUrl)) {
|
|
|
|
|
throw new IOException("Got redirect response code, but Location header was empty or missing");
|
|
|
|
|
}
|
|
|
|
|
previousUrls.add(currentUrl);
|
|
|
|
|
currentUrl = redirectUrl;
|
|
|
|
|
} else if (responseCode == 200) {
|
|
|
|
|
final InputStream is = client.getInputStream();
|
|
|
|
|
return parseResponse(is);
|
|
|
|
|
} else {
|
|
|
|
|
throw new IOException("unhandled response code");
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
if (client != null) client.disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parseResponse(is);
|
|
|
|
|
} finally {
|
|
|
|
|
if (client != null) client.disconnect();
|
|
|
|
|
}
|
|
|
|
|
throw new IOException("max redirects hit");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void sendNotificationReceived(Context context, byte[] mms, String apn,
|
|
|
|
|