From a6cb330dafa5fccdd92376502cb6624b9dc72df6 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sat, 6 Jun 2015 19:56:07 +0530 Subject: added ProxyPrefs --- .../keychain/util/Preferences.java | 41 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java') 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() { -- cgit v1.2.3