remove Preferences check out of HttpDownloader
This is the last Android code in the whole suite of Downloader subclasses, so now we can write JUnit tests for them all, and avoid the fragility of tests running on the emulator.
This commit is contained in:
parent
f2621dcb55
commit
f9063b5058
@ -206,6 +206,9 @@ public class FDroidApp extends Application {
|
|||||||
// the database is locked due to the database updater.
|
// the database is locked due to the database updater.
|
||||||
InstalledAppCacheUpdater.updateInBackground(getApplicationContext());
|
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,
|
// If the user changes the preference to do with filtering rooted apps,
|
||||||
// it is easier to just notify a change in the app provider,
|
// it is easier to just notify a change in the app provider,
|
||||||
// so that the newly updated list will correctly filter relevant apps.
|
// so that the newly updated list will correctly filter relevant apps.
|
||||||
|
@ -6,6 +6,9 @@ import android.os.Build;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -14,6 +17,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import info.guardianproject.netcipher.NetCipher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles shared preferences for FDroid, looking after the names of
|
* Handles shared preferences for FDroid, looking after the names of
|
||||||
* preferences, default values and caching. Needs to be setup in the FDroidApp
|
* 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);
|
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() {
|
public String getProxyHost() {
|
||||||
return preferences.getString(PREF_PROXY_HOST, DEFAULT_PROXY_HOST);
|
return preferences.getString(PREF_PROXY_HOST, DEFAULT_PROXY_HOST);
|
||||||
}
|
}
|
||||||
|
@ -95,12 +95,6 @@ public class HttpDownloader extends Downloader {
|
|||||||
// swap never works with a proxy, its unrouted IP on the same subnet
|
// swap never works with a proxy, its unrouted IP on the same subnet
|
||||||
connection = (HttpURLConnection) sourceUrl.openConnection();
|
connection = (HttpURLConnection) sourceUrl.openConnection();
|
||||||
} else {
|
} 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);
|
connection = NetCipher.getHttpURLConnection(sourceUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,6 +317,7 @@ public class PreferencesFragment extends PreferenceFragment
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
Preferences.get().configureProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user