use Tor to download map tiles if configured to do so

This commit is contained in:
Daniel Gultsch 2018-05-11 12:42:39 +02:00
parent eb1251b389
commit d5a187bafb
5 changed files with 24 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

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