mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-24 23:37:20 +00:00
parent
28e14f47cf
commit
f4e9c4a710
@ -89,9 +89,8 @@ public class MmsCommunication {
|
|||||||
cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(apn);
|
cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(apn);
|
||||||
|
|
||||||
if (cursor == null || !cursor.moveToFirst()) {
|
if (cursor == null || !cursor.moveToFirst()) {
|
||||||
MmsConnectionParameters parameters = getLocalMmsConnectionParameters(context);
|
Log.w(TAG, "Android didn't have a result, querying local parameters.");
|
||||||
Log.w(TAG, "Android didn't have a result, using MMSC parameters: " + parameters.get().get(0).getMmsc() + " // " + parameters.get().get(0).getProxy() + " // " + parameters.get().get(0).getPort());
|
return getLocalMmsConnectionParameters(context);
|
||||||
return parameters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -100,15 +99,14 @@ public class MmsCommunication {
|
|||||||
String port = cursor.getString(cursor.getColumnIndexOrThrow("mmsport"));
|
String port = cursor.getString(cursor.getColumnIndexOrThrow("mmsport"));
|
||||||
|
|
||||||
if (!Util.isEmpty(mmsc)) {
|
if (!Util.isEmpty(mmsc)) {
|
||||||
Log.w(TAG, "Using Android-provided MMSC parameters: " + mmsc + " // " + proxy + " // " + port);
|
Log.w(TAG, "Using Android-provided MMSC parameters.");
|
||||||
return new MmsConnectionParameters(mmsc, proxy, port);
|
return new MmsConnectionParameters(mmsc, proxy, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
|
|
||||||
MmsConnectionParameters parameters = getLocalMmsConnectionParameters(context);
|
Log.w(TAG, "Android provided results were empty, querying local parameters.");
|
||||||
Log.w(TAG, "Android didn't have a result, using MMSC parameters: " + parameters.get().get(0).getMmsc() + " // " + parameters.get().get(0).getProxy() + " // " + parameters.get().get(0).getPort());
|
return getLocalMmsConnectionParameters(context);
|
||||||
return parameters;
|
|
||||||
} catch (SQLiteException sqe) {
|
} catch (SQLiteException sqe) {
|
||||||
Log.w(TAG, sqe);
|
Log.w(TAG, sqe);
|
||||||
} catch (SecurityException se) {
|
} catch (SecurityException se) {
|
||||||
@ -153,7 +151,9 @@ public class MmsCommunication {
|
|||||||
InputStream in = new BufferedInputStream(is);
|
InputStream in = new BufferedInputStream(is);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
Util.copy(in, baos);
|
Util.copy(in, baos);
|
||||||
Log.w(TAG, "received full server response, " + baos.size() + " bytes");
|
|
||||||
|
Log.w(TAG, "Received full server response, " + baos.size() + " bytes");
|
||||||
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,14 +162,16 @@ public class MmsCommunication {
|
|||||||
{
|
{
|
||||||
HttpURLConnection urlConnection;
|
HttpURLConnection urlConnection;
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString);
|
||||||
|
|
||||||
if (proxy != null) {
|
if (proxy != null) {
|
||||||
Log.w(TAG, "constructing http client using a proxy");
|
Log.w(TAG, String.format("Constructing http client using a proxy: (%s:%d)", proxy, port));
|
||||||
Proxy proxyRoute = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, port));
|
Proxy proxyRoute = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, port));
|
||||||
urlConnection = (HttpURLConnection) url.openConnection(proxyRoute);
|
urlConnection = (HttpURLConnection) url.openConnection(proxyRoute);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "constructing http client without proxy");
|
Log.w(TAG, "Constructing http client without proxy");
|
||||||
urlConnection = (HttpURLConnection) url.openConnection();
|
urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
urlConnection.setConnectTimeout(20*1000);
|
urlConnection.setConnectTimeout(20*1000);
|
||||||
urlConnection.setReadTimeout(20*1000);
|
urlConnection.setReadTimeout(20*1000);
|
||||||
urlConnection.setUseCaches(false);
|
urlConnection.setUseCaches(false);
|
||||||
|
@ -21,7 +21,6 @@ import android.net.Uri;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
|
||||||
import ws.com.google.android.mms.pdu.PduParser;
|
import ws.com.google.android.mms.pdu.PduParser;
|
||||||
@ -42,23 +41,18 @@ public class MmsDownloadHelper extends MmsCommunication {
|
|||||||
client.setRequestMethod("GET");
|
client.setRequestMethod("GET");
|
||||||
client.setRequestProperty("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
client.setRequestProperty("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
||||||
|
|
||||||
Log.w(TAG, "connecting to " + url);
|
Log.w(TAG, "Connecting to " + url);
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
||||||
final InputStream is;
|
int responseCode = client.getResponseCode();
|
||||||
try {
|
|
||||||
is = client.getInputStream();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
Log.w(TAG, "failed with response code " + client.getResponseCode() + " / " + client.getResponseMessage());
|
|
||||||
throw ioe;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.w(TAG, "response code was " + client.getResponseCode() + "/" + client.getResponseMessage());
|
Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage());
|
||||||
if (client.getResponseCode() != 200) {
|
|
||||||
|
if (responseCode != 200) {
|
||||||
throw new IOException("non-200 response");
|
throw new IOException("non-200 response");
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseResponse(is);
|
return parseResponse(client.getInputStream());
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null) client.disconnect();
|
if (client != null) client.disconnect();
|
||||||
}
|
}
|
||||||
|
@ -51,38 +51,30 @@ public class MmsSendHelper extends MmsCommunication {
|
|||||||
client.setDoInput(true);
|
client.setDoInput(true);
|
||||||
client.setDoOutput(true);
|
client.setDoOutput(true);
|
||||||
client.setRequestMethod("POST");
|
client.setRequestMethod("POST");
|
||||||
URI targetUrl = new URI(url);
|
|
||||||
|
|
||||||
if (Util.isEmpty(targetUrl.getHost()))
|
|
||||||
throw new IOException("Invalid target host: " + targetUrl.getHost() + " , " + targetUrl);
|
|
||||||
|
|
||||||
client.setRequestProperty("Content-Type", "application/vnd.wap.mms-message");
|
client.setRequestProperty("Content-Type", "application/vnd.wap.mms-message");
|
||||||
client.setRequestProperty("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
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");
|
client.setRequestProperty("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
|
||||||
|
|
||||||
Log.w(TAG, "connecting to " + targetUrl);
|
Log.w(TAG, "Connecting to " + url);
|
||||||
client.connect();
|
client.connect();
|
||||||
Log.w(TAG, "writing mms payload, " + mms.length + " bytes");
|
|
||||||
OutputStream out = new BufferedOutputStream(client.getOutputStream());
|
Log.w(TAG, "Writing mms payload, " + mms.length + " bytes");
|
||||||
|
OutputStream out = client.getOutputStream();
|
||||||
out.write(mms);
|
out.write(mms);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
Log.w(TAG, "payload sent");
|
|
||||||
final InputStream is;
|
Log.w(TAG, "Payload sent");
|
||||||
try {
|
|
||||||
is = client.getInputStream();
|
int responseCode = client.getResponseCode();
|
||||||
} catch (IOException ioe) {
|
|
||||||
Log.w(TAG, "failed with response code " + client.getResponseCode() + " / " + client.getResponseMessage());
|
Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage());
|
||||||
throw ioe;
|
|
||||||
}
|
if (responseCode != 200) {
|
||||||
Log.w(TAG, "response code was " + client.getResponseCode() + "/" + client.getResponseMessage());
|
|
||||||
if (client.getResponseCode() != 200) {
|
|
||||||
throw new IOException("non-200 response");
|
throw new IOException("non-200 response");
|
||||||
}
|
}
|
||||||
return parseResponse(is);
|
|
||||||
} catch (URISyntaxException use) {
|
return parseResponse(client.getInputStream());
|
||||||
Log.w(TAG, use);
|
|
||||||
throw new IOException("Couldn't parse URI.");
|
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null) client.disconnect();
|
if (client != null) client.disconnect();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user