commit 8236f9c6273a9ff4a094fbe9203a14f3a9e0dd75 Author: Amogh Pradeep amoghbl1@gmail.com Date: Fri Jun 12 02:07:45 2015 -0400
Orfox: Centralized proxy applied to CrashReporter, SuggestClient, Distribution, AbstractCommunicator and BaseResources.
Signed-off-by: Amogh Pradeep amoghbl1@gmail.com --- .../base/java/org/mozilla/gecko/CrashReporter.java | 5 ++++- .../base/java/org/mozilla/gecko/SuggestClient.java | 5 ++++- .../mozilla/gecko/distribution/Distribution.java | 5 ++++- mobile/android/base/moz.build | 4 +++- .../java/org/mozilla/gecko/util/ProxySettings.java | 21 +++++++++++++++++++++ .../org/mozilla/gecko/sync/net/BaseResource.java | 4 ++++ .../service/utils/AbstractCommunicator.java | 5 ++++- 7 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/mobile/android/base/java/org/mozilla/gecko/CrashReporter.java b/mobile/android/base/java/org/mozilla/gecko/CrashReporter.java index ce2384a4d4d4..577079954fae 100644 --- a/mobile/android/base/java/org/mozilla/gecko/CrashReporter.java +++ b/mobile/android/base/java/org/mozilla/gecko/CrashReporter.java @@ -17,11 +17,14 @@ import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.net.Proxy; +import java.net.InetSocketAddress; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.util.zip.GZIPOutputStream;
import org.mozilla.gecko.AppConstants.Versions; +import org.mozilla.gecko.util.ProxySettings;
import android.annotation.SuppressLint; import android.app.AlertDialog; @@ -366,7 +369,7 @@ public class CrashReporter extends AppCompatActivity Log.i(LOGTAG, "server url: " + spec); try { URL url = new URL(spec); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(ProxySettings.getProxy()); conn.setRequestMethod("POST"); String boundary = generateBoundary(); conn.setDoOutput(true); diff --git a/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java b/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java index e43bbef1f48c..673feb54abdc 100644 --- a/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java +++ b/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java @@ -7,6 +7,8 @@ package org.mozilla.gecko; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.Proxy; +import java.net.InetSocketAddress; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; @@ -15,6 +17,7 @@ import java.util.ArrayList; import org.json.JSONArray; import org.mozilla.gecko.annotation.RobocopTarget; import org.mozilla.gecko.util.HardwareUtils; +import org.mozilla.gecko.util.ProxySettings;
import android.content.Context; import android.text.TextUtils; @@ -87,7 +90,7 @@ public class SuggestClient { HttpURLConnection urlConnection = null; InputStream in = null; try { - urlConnection = (HttpURLConnection) url.openConnection(); + urlConnection = (HttpURLConnection) url.openConnection(ProxySettings.getProxy()); urlConnection.setConnectTimeout(mTimeout); urlConnection.setRequestProperty("User-Agent", USER_AGENT); in = new BufferedInputStream(urlConnection.getInputStream()); diff --git a/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java b/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java index a7b0fe32d360..4b272109a0fc 100644 --- a/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java +++ b/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java @@ -18,6 +18,8 @@ import java.net.SocketException; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; +import java.net.Proxy; +import java.net.InetSocketAddress; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; @@ -44,6 +46,7 @@ import org.mozilla.gecko.Telemetry; import org.mozilla.gecko.annotation.JNITarget; import org.mozilla.gecko.util.FileUtils; import org.mozilla.gecko.util.HardwareUtils; +import org.mozilla.gecko.util.ProxySettings; import org.mozilla.gecko.util.ThreadUtils;
import android.app.Activity; @@ -522,7 +525,7 @@ public class Distribution { Log.v(LOGTAG, "Downloading referred distribution: " + uri);
try { - final HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); + final HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(ProxySettings.getProxy());
// If the Search Activity starts, and we handle the referrer intent, this'll return // null. Recover gracefully in this case. diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index 4dbb1c25fdab..9d93e47b222d 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -149,8 +149,9 @@ gujar.sources += [geckoview_source_dir + 'java/org/mozilla/gecko/' + x for x in 'util/NonEvictingLruCache.java', 'util/PrefUtils.java', 'util/ProxySelector.java', + 'util/ProxySettings.java', 'util/publicsuffix/PublicSuffix.java', - 'util/publicsuffix/PublicSuffixPatterns.java', + 'util/publicsuffix/PublicSuffixPatterns.java', 'util/RawResource.java', 'util/StringUtils.java', 'util/ThreadUtils.java', @@ -165,6 +166,7 @@ gujar.extra_jars = [ CONFIG['ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB'], 'constants.jar', 'gecko-mozglue.jar', + 'sync-thirdparty.jar', ] gujar.javac_flags += ['-Xlint:all,-deprecation']
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ProxySettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ProxySettings.java new file mode 100644 index 000000000000..0f5d363d543f --- /dev/null +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ProxySettings.java @@ -0,0 +1,21 @@ +package org.mozilla.gecko.util; + +import java.net.InetSocketAddress; +import java.net.Proxy; + +import ch.boye.httpclientandroidlib.HttpHost; + +public class ProxySettings { + private static final String TOR_PROXY_ADDRESS = "127.0.0.1"; + private static final int TOR_PROXY_PORT = 8118; + + public static Proxy getProxy() { + // TODO make configurable + return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(TOR_PROXY_ADDRESS, TOR_PROXY_PORT)); + } + + public static HttpHost getProxyHost() { + // TODO make configurable + return new HttpHost(TOR_PROXY_ADDRESS, TOR_PROXY_PORT); + } +} diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/net/BaseResource.java b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/net/BaseResource.java index 60bbc86bbca7..b52c38d1ab07 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/net/BaseResource.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/net/BaseResource.java @@ -54,6 +54,9 @@ import ch.boye.httpclientandroidlib.params.HttpProtocolParams; import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; import ch.boye.httpclientandroidlib.protocol.HttpContext; import ch.boye.httpclientandroidlib.util.EntityUtils; +import ch.boye.httpclientandroidlib.HttpHost; +import ch.boye.httpclientandroidlib.conn.params.ConnRoutePNames; +import org.mozilla.gecko.util.ProxySettings;
/** * Provide simple HTTP access to a Sync server or similar. @@ -215,6 +218,7 @@ public class BaseResource implements Resource { // We could reuse these client instances, except that we mess around // with their parameters… so we'd need a pool of some kind. client = new DefaultHttpClient(getConnectionManager()); + client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, ProxySettings.getProxyHost());
// TODO: Eventually we should use Apache HttpAsyncClient. It's not out of alpha yet. // Until then, we synchronously make the request, then invoke our delegate's callback. diff --git a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/utils/AbstractCommunicator.java b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/utils/AbstractCommunicator.java index 70816371a39c..f67b8bd45711 100644 --- a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/utils/AbstractCommunicator.java +++ b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/utils/AbstractCommunicator.java @@ -17,6 +17,8 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.net.Proxy; +import java.net.InetSocketAddress;
public abstract class AbstractCommunicator {
@@ -73,7 +75,8 @@ public abstract class AbstractCommunicator { sMozApiKey = prefs.getMozApiKey(); } URL url = new URL(getUrlString() + "?key=" + sMozApiKey); - mHttpURLConnection = (HttpURLConnection) url.openConnection(); + Proxy torProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8118)); + mHttpURLConnection = (HttpURLConnection) url.openConnection(torProxy); mHttpURLConnection.setRequestMethod("POST"); } catch (MalformedURLException e) { throw new IllegalArgumentException(e);
tor-commits@lists.torproject.org