From d5a187bafba68b0c210f8466299d9cbf2cfd2452 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 11 May 2018 12:42:39 +0200 Subject: [PATCH] use Tor to download map tiles if configured to do so --- .../conversations/http/HttpConnectionManager.java | 2 +- .../conversations/http/HttpDownloadConnection.java | 4 ++-- .../conversations/http/HttpUploadConnection.java | 2 +- .../siacs/conversations/ui/LocationActivity.java | 14 ++++++++++++++ .../eu/siacs/conversations/ui/XmppActivity.java | 7 ++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java b/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java index e72f484a7..02b9a2388 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java @@ -77,7 +77,7 @@ public class HttpConnectionManager extends AbstractConnectionManager { } } - public Proxy getProxy() throws IOException { + public static Proxy getProxy() throws IOException { return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByAddress(new byte[]{127,0,0,1}), 8118)); } } diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index b8862244e..60f180bde 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -222,7 +222,7 @@ public class HttpDownloadConnection implements Transferable { changeStatus(STATUS_CHECKING); HttpURLConnection connection; if (mUseTor) { - connection = (HttpURLConnection) mUrl.openConnection(mHttpConnectionManager.getProxy()); + connection = (HttpURLConnection) mUrl.openConnection(HttpConnectionManager.getProxy()); } else { connection = (HttpURLConnection) mUrl.openConnection(); } @@ -290,7 +290,7 @@ public class HttpDownloadConnection implements Transferable { try { wakeLock.acquire(); if (mUseTor) { - connection = (HttpURLConnection) mUrl.openConnection(mHttpConnectionManager.getProxy()); + connection = (HttpURLConnection) mUrl.openConnection(HttpConnectionManager.getProxy()); } else { connection = (HttpURLConnection) mUrl.openConnection(); } diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index c7625e175..9538d3cb6 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -180,7 +180,7 @@ public class HttpUploadConnection implements Transferable { wakeLock.acquire(readTimeout); Log.d(Config.LOGTAG, "uploading to " + mPutUrl.toString()+ " w/ read timeout of "+readTimeout+"s"); if (mUseTor) { - connection = (HttpURLConnection) mPutUrl.openConnection(mHttpConnectionManager.getProxy()); + connection = (HttpURLConnection) mPutUrl.openConnection(HttpConnectionManager.getProxy()); } else { connection = (HttpURLConnection) mPutUrl.openConnection(); } diff --git a/src/main/java/eu/siacs/conversations/ui/LocationActivity.java b/src/main/java/eu/siacs/conversations/ui/LocationActivity.java index b335257a5..63f7393d7 100644 --- a/src/main/java/eu/siacs/conversations/ui/LocationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/LocationActivity.java @@ -14,6 +14,7 @@ import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.Settings; +import android.support.annotation.BoolRes; import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.Log; @@ -29,10 +30,12 @@ import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.Overlay; import java.io.File; +import java.io.IOException; import eu.siacs.conversations.BuildConfig; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; +import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.ui.util.LocationHelper; import eu.siacs.conversations.ui.widget.Marker; import eu.siacs.conversations.ui.widget.MyLocation; @@ -100,6 +103,13 @@ public abstract class LocationActivity extends ActionBarActivity implements Loca final IConfigurationProvider config = Configuration.getInstance(); config.load(ctx, getPreferences()); config.setUserAgentValue(BuildConfig.APPLICATION_ID + "_" + BuildConfig.VERSION_CODE); + if (Config.FORCE_ORBOT || getBooleanPreference("use_tor", R.bool.use_tor)) { + try { + config.setHttpProxy(HttpConnectionManager.getProxy()); + } catch (IOException e) { + throw new RuntimeException("Unable to configure proxy"); + } + } final File f = new File(ctx.getCacheDir() + "/tiles"); try { @@ -286,6 +296,10 @@ public abstract class LocationActivity extends ActionBarActivity implements Loca return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } + protected boolean getBooleanPreference(String name, @BoolRes int res) { + return getPreferences().getBoolean(name, getResources().getBoolean(res)); + } + protected boolean isLocationEnabled() { try { final int locationMode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 340123141..3a69d55ca 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -33,6 +33,7 @@ import android.os.IBinder; import android.os.PowerManager; import android.os.SystemClock; import android.preference.PreferenceManager; +import android.support.annotation.BoolRes; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog.Builder; @@ -399,7 +400,7 @@ public abstract class XmppActivity extends ActionBarActivity { setTheme(this.mTheme); this.mUsingEnterKey = usingEnterKey(); - mUseSubject = getPreferences().getBoolean("use_subject", getResources().getBoolean(R.bool.use_subject)); + mUseSubject = getBooleanPreference("use_subject", R.bool.use_subject); } protected boolean isCameraFeatureAvailable() { @@ -449,6 +450,10 @@ public abstract class XmppActivity extends ActionBarActivity { return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } + protected boolean getBooleanPreference(String name, @BoolRes int res) { + return getPreferences().getBoolean(name, getResources().getBoolean(res)); + } + public boolean useSubjectToIdentifyConference() { return mUseSubject; }