diff --git a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java index 9db97b91d..df06334e8 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java @@ -206,6 +206,9 @@ public class FDroidApp extends Application { // the database is locked due to the database updater. InstalledAppCacheUpdater.updateInBackground(getApplicationContext()); + // make sure the current proxy stuff is configured + Preferences.get().configureProxy(); + // If the user changes the preference to do with filtering rooted apps, // it is easier to just notify a change in the app provider, // so that the newly updated list will correctly filter relevant apps. diff --git a/F-Droid/src/org/fdroid/fdroid/Preferences.java b/F-Droid/src/org/fdroid/fdroid/Preferences.java index ed9bc4df1..c436694a2 100644 --- a/F-Droid/src/org/fdroid/fdroid/Preferences.java +++ b/F-Droid/src/org/fdroid/fdroid/Preferences.java @@ -6,6 +6,9 @@ import android.os.Build; import android.preference.PreferenceManager; import android.util.Log; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.SocketAddress; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -14,6 +17,8 @@ import java.util.List; import java.util.Map; import java.util.Random; +import info.guardianproject.netcipher.NetCipher; + /** * Handles shared preferences for FDroid, looking after the names of * preferences, default values and caching. Needs to be setup in the FDroidApp @@ -178,6 +183,18 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh return preferences.getBoolean(PREF_ENABLE_PROXY, DEFAULT_ENABLE_PROXY); } + /** + * Configure the proxy settings based on whether its enabled and set up. This must be + * run once at app startup, then whenever any of these settings changes. + */ + public void configureProxy() { + if (isProxyEnabled()) { + // if "Use Tor" is set, NetCipher will ignore these proxy settings + SocketAddress sa = new InetSocketAddress(getProxyHost(), getProxyPort()); + NetCipher.setProxy(new Proxy(Proxy.Type.HTTP, sa)); + } + } + public String getProxyHost() { return preferences.getString(PREF_PROXY_HOST, DEFAULT_PROXY_HOST); } diff --git a/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java index bebd55977..a7bfac24d 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java @@ -95,12 +95,6 @@ public class HttpDownloader extends Downloader { // swap never works with a proxy, its unrouted IP on the same subnet connection = (HttpURLConnection) sourceUrl.openConnection(); } else { - Preferences prefs = Preferences.get(); - if (prefs.isProxyEnabled()) { - // if "Use Tor" is set, NetCipher will ignore these proxy settings - SocketAddress sa = new InetSocketAddress(prefs.getProxyHost(), prefs.getProxyPort()); - NetCipher.setProxy(new Proxy(Proxy.Type.HTTP, sa)); - } connection = NetCipher.getHttpURLConnection(sourceUrl); } diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java index 576aaafa7..c6007348e 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java @@ -317,6 +317,7 @@ public class PreferencesFragment extends PreferenceFragment public void onPause() { super.onPause(); getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); + Preferences.get().configureProxy(); } @Override