add "HTTP Proxy" preference to support Tor, I2P, or any other proxy
This is the most basic support for channeling all downloads through Tor or I2P. This does not include Orbot integration, so the use will have to know to start Orbot before using this. I don't know anything about I2P. closes #2367 https://dev.guardianproject.info/issues/2367 https://f-droid.org/repository/issues/?do=view_issue&issue=404 https://f-droid.org/repository/issues/?do=view_issue&issue=424
This commit is contained in:
parent
ff5d2b571f
commit
b7f0195234
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
* use FDroid repos on Tor Hidden Services (.onion addresses)
|
* use FDroid repos on Tor Hidden Services (.onion addresses)
|
||||||
|
|
||||||
|
* support for a HTTP Proxy in Preferences
|
||||||
|
|
||||||
* directly send installed apps to other devices via Bluetooth and Android Beam
|
* directly send installed apps to other devices via Bluetooth and Android Beam
|
||||||
(NFC+Bluetooth), also compatible with Samsung/HTC S-Beam
|
(NFC+Bluetooth), also compatible with Samsung/HTC S-Beam
|
||||||
|
|
||||||
|
@ -197,6 +197,14 @@
|
|||||||
<string name="qr_wizard_download_instructions">Scan this QR Code to connect to the website for getting started.</string>
|
<string name="qr_wizard_download_instructions">Scan this QR Code to connect to the website for getting started.</string>
|
||||||
<string name="send_fdroid_via_wifi">Send FDroid via WiFi…</string>
|
<string name="send_fdroid_via_wifi">Send FDroid via WiFi…</string>
|
||||||
|
|
||||||
|
<string name="proxy">Proxy</string>
|
||||||
|
<string name="enable_proxy_title">Enable HTTP Proxy</string>
|
||||||
|
<string name="enable_proxy_summary">Configure HTTP Proxy for all network requests</string>
|
||||||
|
<string name="proxy_host">Proxy Host</string>
|
||||||
|
<string name="proxy_host_summary">Configure your proxy\'s hostname (e.g. 127.0.0.1)</string>
|
||||||
|
<string name="proxy_port">Proxy Port</string>
|
||||||
|
<string name="proxy_port_summary">Configure your proxy\'s port number (e.g. 8118)</string>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
status_download takes four parameters:
|
status_download takes four parameters:
|
||||||
- Repository (url)
|
- Repository (url)
|
||||||
|
@ -70,4 +70,19 @@
|
|||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="systemInstaller" />
|
android:key="systemInstaller" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory android:title="@string/proxy" >
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="enableProxy"
|
||||||
|
android:title="@string/enable_proxy_title"
|
||||||
|
android:summary="@string/enable_proxy_summary" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="proxyHost"
|
||||||
|
android:title="@string/proxy_host"
|
||||||
|
android:summary="@string/proxy_host_summary" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="proxyPort"
|
||||||
|
android:title="@string/proxy_port"
|
||||||
|
android:summary="@string/proxy_port_summary" />
|
||||||
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@ -53,6 +53,9 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
|||||||
public static final String PREF_LOCAL_REPO_BONJOUR = "localRepoBonjour";
|
public static final String PREF_LOCAL_REPO_BONJOUR = "localRepoBonjour";
|
||||||
public static final String PREF_LOCAL_REPO_NAME = "localRepoName";
|
public static final String PREF_LOCAL_REPO_NAME = "localRepoName";
|
||||||
public static final String PREF_LOCAL_REPO_HTTPS = "localRepoHttps";
|
public static final String PREF_LOCAL_REPO_HTTPS = "localRepoHttps";
|
||||||
|
public static final String PREF_ENABLE_PROXY = "enableProxy";
|
||||||
|
public static final String PREF_PROXY_HOST = "proxyHost";
|
||||||
|
public static final String PREF_PROXY_PORT = "proxyPort";
|
||||||
|
|
||||||
private static final boolean DEFAULT_COMPACT_LAYOUT = false;
|
private static final boolean DEFAULT_COMPACT_LAYOUT = false;
|
||||||
private static final boolean DEFAULT_ROOTED = true;
|
private static final boolean DEFAULT_ROOTED = true;
|
||||||
@ -64,6 +67,9 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
|||||||
private static final boolean DEFAULT_INCOMP_VER = false;
|
private static final boolean DEFAULT_INCOMP_VER = false;
|
||||||
private static final boolean DEFAULT_EXPERT = false;
|
private static final boolean DEFAULT_EXPERT = false;
|
||||||
private static final boolean DEFAULT_PERMISSIONS = false;
|
private static final boolean DEFAULT_PERMISSIONS = false;
|
||||||
|
private static final boolean DEFAULT_ENABLE_PROXY = false;
|
||||||
|
public static final String DEFAULT_PROXY_HOST = "127.0.0.1";
|
||||||
|
public static final int DEFAULT_PROXY_PORT = 8118;
|
||||||
|
|
||||||
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
|
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
|
||||||
private boolean filterAppsRequiringRoot = DEFAULT_ROOTED;
|
private boolean filterAppsRequiringRoot = DEFAULT_ROOTED;
|
||||||
@ -88,11 +94,11 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
|||||||
private void uninitialize(String key) {
|
private void uninitialize(String key) {
|
||||||
initialized.put(key, false);
|
initialized.put(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRootInstallerEnabled() {
|
public boolean isRootInstallerEnabled() {
|
||||||
return preferences.getBoolean(PREF_ROOT_INSTALLER, DEFAULT_ROOT_INSTALLER);
|
return preferences.getBoolean(PREF_ROOT_INSTALLER, DEFAULT_ROOT_INSTALLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSystemInstallerEnabled() {
|
public boolean isSystemInstallerEnabled() {
|
||||||
return preferences.getBoolean(PREF_SYSTEM_INSTALLER, DEFAULT_SYSTEM_INSTALLER);
|
return preferences.getBoolean(PREF_SYSTEM_INSTALLER, DEFAULT_SYSTEM_INSTALLER);
|
||||||
}
|
}
|
||||||
@ -126,6 +132,28 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
|||||||
return preferences.getString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
|
return preferences.getString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProxyEnabled() {
|
||||||
|
return preferences.getBoolean(PREF_ENABLE_PROXY, DEFAULT_ENABLE_PROXY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyHost() {
|
||||||
|
return preferences.getString(PREF_PROXY_HOST, DEFAULT_PROXY_HOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProxyPort() {
|
||||||
|
String port = preferences.getString(PREF_PROXY_PORT, String.valueOf(DEFAULT_PROXY_PORT));
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(port);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// hack until this can be a number-only preference
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(port.replaceAll("[^0-9]", ""));
|
||||||
|
} catch (Exception e1) {
|
||||||
|
return DEFAULT_PROXY_PORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasCompactLayout() {
|
public boolean hasCompactLayout() {
|
||||||
if (!isInitialized(PREF_COMPACT_LAYOUT)) {
|
if (!isInitialized(PREF_COMPACT_LAYOUT)) {
|
||||||
initialize(PREF_COMPACT_LAYOUT);
|
initialize(PREF_COMPACT_LAYOUT);
|
||||||
|
@ -3,12 +3,17 @@ package org.fdroid.fdroid.net;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
@ -70,7 +75,14 @@ public class HttpDownloader extends Downloader {
|
|||||||
protected void setupConnection() throws IOException {
|
protected void setupConnection() throws IOException {
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
return;
|
return;
|
||||||
connection = (HttpURLConnection) sourceUrl.openConnection();
|
Preferences prefs = Preferences.get();
|
||||||
|
if (prefs.isProxyEnabled()) {
|
||||||
|
SocketAddress sa = new InetSocketAddress(prefs.getProxyHost(), prefs.getProxyPort());
|
||||||
|
Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
|
||||||
|
connection = (HttpURLConnection) sourceUrl.openConnection(proxy);
|
||||||
|
} else {
|
||||||
|
connection = (HttpURLConnection) sourceUrl.openConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doDownload() throws IOException, InterruptedException {
|
protected void doDownload() throws IOException, InterruptedException {
|
||||||
|
@ -7,6 +7,8 @@ import android.preference.CheckBoxPreference;
|
|||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.PreferencesActivity;
|
import org.fdroid.fdroid.PreferencesActivity;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
@ -34,7 +36,10 @@ public class PreferenceFragment
|
|||||||
Preferences.PREF_CACHE_APK,
|
Preferences.PREF_CACHE_APK,
|
||||||
Preferences.PREF_EXPERT,
|
Preferences.PREF_EXPERT,
|
||||||
Preferences.PREF_ROOT_INSTALLER,
|
Preferences.PREF_ROOT_INSTALLER,
|
||||||
Preferences.PREF_SYSTEM_INSTALLER
|
Preferences.PREF_SYSTEM_INSTALLER,
|
||||||
|
Preferences.PREF_ENABLE_PROXY,
|
||||||
|
Preferences.PREF_PROXY_HOST,
|
||||||
|
Preferences.PREF_PROXY_PORT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -144,6 +149,35 @@ public class PreferenceFragment
|
|||||||
onoffSummary(key, R.string.system_installer_on,
|
onoffSummary(key, R.string.system_installer_on,
|
||||||
R.string.system_installer_off);
|
R.string.system_installer_off);
|
||||||
|
|
||||||
|
} else if (key.equals(Preferences.PREF_ENABLE_PROXY)) {
|
||||||
|
CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
|
||||||
|
pref.setSummary(R.string.enable_proxy_summary);
|
||||||
|
Preference h = findPreference(Preferences.PREF_PROXY_HOST);
|
||||||
|
Preference p = findPreference(Preferences.PREF_PROXY_PORT);
|
||||||
|
if (pref.isChecked()) {
|
||||||
|
h.setEnabled(true);
|
||||||
|
p.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
h.setEnabled(false);
|
||||||
|
p.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (key.equals(Preferences.PREF_PROXY_HOST)) {
|
||||||
|
EditTextPreference textPref = (EditTextPreference) findPreference(key);
|
||||||
|
String text = Preferences.get().getProxyHost();
|
||||||
|
if (TextUtils.isEmpty(text) || text.equals(Preferences.DEFAULT_PROXY_HOST))
|
||||||
|
textPref.setSummary(R.string.proxy_host_summary);
|
||||||
|
else
|
||||||
|
textPref.setSummary(text);
|
||||||
|
|
||||||
|
} else if (key.equals(Preferences.PREF_PROXY_PORT)) {
|
||||||
|
EditTextPreference textPref = (EditTextPreference) findPreference(key);
|
||||||
|
int port = Preferences.get().getProxyPort();
|
||||||
|
if (port == Preferences.DEFAULT_PROXY_PORT)
|
||||||
|
textPref.setSummary(R.string.proxy_port_summary);
|
||||||
|
else
|
||||||
|
textPref.setSummary(String.valueOf(port));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user