added ProxyPrefs

This commit is contained in:
Adithya Abraham Philip
2015-06-06 19:56:07 +05:30
parent 0883784ce1
commit a6cb330daf
2 changed files with 50 additions and 3 deletions

View File

@@ -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() {