diff options
author | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-06-06 19:56:07 +0530 |
---|---|---|
committer | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-07-03 20:46:15 +0530 |
commit | a6cb330dafa5fccdd92376502cb6624b9dc72df6 (patch) | |
tree | fc32295a8b3346a2f43bd68e9a14c09ede3709b5 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util | |
parent | 0883784ce1a2f85100ada0a84c1f604ad458dd96 (diff) | |
download | open-keychain-a6cb330dafa5fccdd92376502cb6624b9dc72df6.tar.gz open-keychain-a6cb330dafa5fccdd92376502cb6624b9dc72df6.tar.bz2 open-keychain-a6cb330dafa5fccdd92376502cb6624b9dc72df6.zip |
added ProxyPrefs
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java index 6a7d6d3eb..7c8e5f1ce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java @@ -22,10 +22,12 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; +import info.guardianproject.onionkit.ui.OrbotHelper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants.Pref; import org.sufficientlysecure.keychain.R; +import java.net.InetSocketAddress; import java.net.Proxy; import java.util.ArrayList; import java.util.Arrays; @@ -212,7 +214,6 @@ public class Preferences { } - public void setUseArmor(boolean useArmor) { SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putBoolean(Pref.USE_ARMOR, useArmor); @@ -291,14 +292,48 @@ public class Preferences { String type = mSharedPreferences.getString(Pref.PROXY_TYPE, typeHttp); - if(type.equals(typeHttp)) return Proxy.Type.HTTP; - else if(type.equals(typeSocks)) return Proxy.Type.SOCKS; + if (type.equals(typeHttp)) return Proxy.Type.HTTP; + else if (type.equals(typeSocks)) return Proxy.Type.SOCKS; else { // shouldn't happen Log.e(Constants.TAG, "Invalid Proxy Type in preferences"); return null; } } + public ProxyPrefs getProxyPrefs() { + Proxy proxy = null; + boolean useTor = getUseTorProxy(); + boolean useNormalProxy = getUseNormalProxy(); + + if (useTor) { + proxy = Constants.Orbot.PROXY; + } + else if (useNormalProxy) { + proxy = new Proxy(getProxyType(), new InetSocketAddress(getProxyHost(), getProxyPort())); + } + + return new ProxyPrefs(getUseTorProxy(), getUseNormalProxy(), proxy); + } + + public static class ProxyPrefs { + public final Proxy proxy; + public final boolean torEnabled; + public final boolean normalPorxyEnabled; + + /** + * torEnabled and normalProxyEnabled are not expected to both be true + * + * @param torEnabled if Tor is to be used + * @param normalPorxyEnabled if user-specified proxy is to be used + * @param proxy proxy to use, leave null if none + */ + public ProxyPrefs(boolean torEnabled, boolean normalPorxyEnabled, Proxy proxy) { + this.torEnabled = torEnabled; + this.normalPorxyEnabled = normalPorxyEnabled; + this.proxy = proxy; + } + } + // proxy preference functions ends here public CloudSearchPrefs getCloudSearchPrefs() { |