mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 09:12:16 -05:00
added ProxyPrefs
This commit is contained in:
parent
a959b663b4
commit
3b6cd57599
@ -24,6 +24,8 @@ import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
|
||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
|
||||
public final class Constants {
|
||||
|
||||
@ -99,6 +101,16 @@ public final class Constants {
|
||||
public static final String PROXY_TYPE = "proxyType";
|
||||
}
|
||||
|
||||
/**
|
||||
* information to connect to Orbot's localhost HTTP proxy
|
||||
*/
|
||||
public static final class Orbot {
|
||||
public static final String PROXY_HOST = "127.0.0.1";
|
||||
public static final int PROXY_PORT = 8118;
|
||||
public static final Proxy.Type PROXY_TYPE = Proxy.Type.HTTP;
|
||||
public static final Proxy PROXY = new Proxy(PROXY_TYPE, new InetSocketAddress(PROXY_HOST, PROXY_PORT));
|
||||
}
|
||||
|
||||
public static final class Defaults {
|
||||
public static final String KEY_SERVERS = "hkps://hkps.pool.sks-keyservers.net, hkps://pgp.mit.edu";
|
||||
public static final int PREF_VERSION = 4;
|
||||
|
@ -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;
|
||||
@ -208,7 +210,6 @@ public class Preferences {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setUseArmor(boolean useArmor) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.USE_ARMOR, useArmor);
|
||||
@ -287,14 +288,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() {
|
||||
|
Loading…
Reference in New Issue
Block a user