allow country exit node select to persist
This commit is contained in:
parent
b2081789f5
commit
3b41365708
|
@ -72,6 +72,7 @@ import java.net.URLEncoder;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
|
@ -306,32 +307,40 @@ public class OrbotMainActivity extends Activity
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Locale[] locale = Locale.getAvailableLocales();
|
|
||||||
ArrayList<String> countries = new ArrayList<String>();
|
|
||||||
countries.add("World (best)");
|
|
||||||
countries.add("US");
|
|
||||||
countries.add("DE");
|
|
||||||
countries.add("CA");
|
|
||||||
countries.add("FR");
|
|
||||||
|
|
||||||
|
String currentExit = Prefs.getExitNodes();
|
||||||
|
int selIdx = -1;
|
||||||
|
|
||||||
|
ArrayList<String> cList = new ArrayList<String>();
|
||||||
|
cList.add(0, "WORLD");
|
||||||
|
|
||||||
|
for (int i = 0; i < TorServiceConstants.COUNTRY_CODES.length; i++)
|
||||||
|
{
|
||||||
|
Locale locale = new Locale("",TorServiceConstants.COUNTRY_CODES[i]);
|
||||||
|
cList.add(locale.getDisplayCountry());
|
||||||
|
|
||||||
|
if (currentExit.contains(TorServiceConstants.COUNTRY_CODES[i]))
|
||||||
|
selIdx = i+1;
|
||||||
|
}
|
||||||
|
|
||||||
spnCountries = (Spinner)findViewById(R.id.spinnerCountry);
|
spnCountries = (Spinner)findViewById(R.id.spinnerCountry);
|
||||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, countries);
|
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, cList);
|
||||||
spnCountries.setAdapter(adapter);
|
spnCountries.setAdapter(adapter);
|
||||||
|
|
||||||
|
if (selIdx != -1)
|
||||||
|
spnCountries.setSelection(selIdx);
|
||||||
|
|
||||||
spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() {
|
spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
|
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
|
||||||
// your code here
|
// your code here
|
||||||
|
|
||||||
String country = (String)spnCountries.getItemAtPosition(position);
|
String country = null;
|
||||||
|
|
||||||
if (position == 0)
|
if (position == 0)
|
||||||
country = "";
|
country = "";
|
||||||
else
|
else
|
||||||
country = '{' + country.toLowerCase() + '}';
|
country = '{' + TorServiceConstants.COUNTRY_CODES[position-1] + '}';
|
||||||
|
|
||||||
Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
|
Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
|
||||||
torService.setAction(TorServiceConstants.CMD_SET_EXIT);
|
torService.setAction(TorServiceConstants.CMD_SET_EXIT);
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.torproject.android;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.torproject.android.service.TorServiceUtils;
|
import org.torproject.android.service.TorServiceUtils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -23,6 +25,7 @@ public class Prefs {
|
||||||
private final static String PREF_TRANSPROXY_REFRESH = "pref_transproxy_refresh";
|
private final static String PREF_TRANSPROXY_REFRESH = "pref_transproxy_refresh";
|
||||||
private final static String PREF_USE_SYSTEM_IPTABLES = "pref_use_sys_iptables";
|
private final static String PREF_USE_SYSTEM_IPTABLES = "pref_use_sys_iptables";
|
||||||
private final static String PREF_USE_VPN = "pref_vpn";
|
private final static String PREF_USE_VPN = "pref_vpn";
|
||||||
|
private final static String PREF_EXIT_NODES = "pref_exit_nodes";
|
||||||
|
|
||||||
private static SharedPreferences prefs;
|
private static SharedPreferences prefs;
|
||||||
|
|
||||||
|
@ -118,4 +121,14 @@ public class Prefs {
|
||||||
public static void putStartOnBoot(boolean value) {
|
public static void putStartOnBoot(boolean value) {
|
||||||
putBoolean(PREF_START_ON_BOOT, value);
|
putBoolean(PREF_START_ON_BOOT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getExitNodes ()
|
||||||
|
{
|
||||||
|
return prefs.getString(PREF_EXIT_NODES, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setExitNodes (String exits)
|
||||||
|
{
|
||||||
|
putString(PREF_EXIT_NODES,exits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1414,72 +1414,72 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
if (mCurrentStatus == STATUS_STARTING && TextUtils.equals(status, "BUILT"))
|
if (mCurrentStatus == STATUS_STARTING && TextUtils.equals(status, "BUILT"))
|
||||||
sendCallbackStatus(STATUS_ON);
|
sendCallbackStatus(STATUS_ON);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("Circuit (");
|
sb.append("Circuit (");
|
||||||
sb.append((circID));
|
sb.append((circID));
|
||||||
sb.append(") ");
|
sb.append(") ");
|
||||||
sb.append(status);
|
sb.append(status);
|
||||||
sb.append(": ");
|
sb.append(": ");
|
||||||
|
|
||||||
StringTokenizer st = new StringTokenizer(path,",");
|
StringTokenizer st = new StringTokenizer(path,",");
|
||||||
Node node = null;
|
Node node = null;
|
||||||
|
|
||||||
while (st.hasMoreTokens())
|
while (st.hasMoreTokens())
|
||||||
|
{
|
||||||
|
String nodePath = st.nextToken();
|
||||||
|
node = new Node();
|
||||||
|
|
||||||
|
String[] nodeParts;
|
||||||
|
|
||||||
|
if (nodePath.contains("="))
|
||||||
|
nodeParts = nodePath.split("=");
|
||||||
|
else
|
||||||
|
nodeParts = nodePath.split("~");
|
||||||
|
|
||||||
|
if (nodeParts.length == 1)
|
||||||
{
|
{
|
||||||
String nodePath = st.nextToken();
|
node.id = nodeParts[0].substring(1);
|
||||||
node = new Node();
|
node.name = node.id;
|
||||||
|
}
|
||||||
String[] nodeParts;
|
else if (nodeParts.length == 2)
|
||||||
|
{
|
||||||
if (nodePath.contains("="))
|
node.id = nodeParts[0].substring(1);
|
||||||
nodeParts = nodePath.split("=");
|
node.name = nodeParts[1];
|
||||||
else
|
|
||||||
nodeParts = nodePath.split("~");
|
|
||||||
|
|
||||||
if (nodeParts.length == 1)
|
|
||||||
{
|
|
||||||
node.id = nodeParts[0].substring(1);
|
|
||||||
node.name = node.id;
|
|
||||||
}
|
|
||||||
else if (nodeParts.length == 2)
|
|
||||||
{
|
|
||||||
node.id = nodeParts[0].substring(1);
|
|
||||||
node.name = nodeParts[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
node.status = status;
|
|
||||||
|
|
||||||
sb.append(node.name);
|
|
||||||
|
|
||||||
if (st.hasMoreTokens())
|
|
||||||
sb.append (" > ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Prefs.useDebugLogging())
|
node.status = status;
|
||||||
debug(sb.toString());
|
|
||||||
else if(status.equals("BUILT"))
|
|
||||||
logNotice(sb.toString());
|
|
||||||
else if (status.equals("CLOSED"))
|
|
||||||
logNotice(sb.toString());
|
|
||||||
|
|
||||||
if (Prefs.expandedNotifications())
|
sb.append(node.name);
|
||||||
{
|
|
||||||
//get IP from last nodename
|
|
||||||
if(status.equals("BUILT")){
|
|
||||||
|
|
||||||
if (node.ipAddress == null)
|
if (st.hasMoreTokens())
|
||||||
mExecutor.execute(new ExternalIPFetcher(node));
|
sb.append (" > ");
|
||||||
|
}
|
||||||
|
|
||||||
hmBuiltNodes.put(node.id, node);
|
if (Prefs.useDebugLogging())
|
||||||
}
|
debug(sb.toString());
|
||||||
|
else if(status.equals("BUILT"))
|
||||||
|
logNotice(sb.toString());
|
||||||
|
else if (status.equals("CLOSED"))
|
||||||
|
logNotice(sb.toString());
|
||||||
|
|
||||||
if (status.equals("CLOSED"))
|
if (Prefs.expandedNotifications())
|
||||||
{
|
{
|
||||||
hmBuiltNodes.remove(node.id);
|
//get IP from last nodename
|
||||||
|
if(status.equals("BUILT")){
|
||||||
|
|
||||||
}
|
if (node.ipAddress == null)
|
||||||
|
mExecutor.execute(new ExternalIPFetcher(node));
|
||||||
|
|
||||||
|
hmBuiltNodes.put(node.id, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status.equals("CLOSED"))
|
||||||
|
{
|
||||||
|
hmBuiltNodes.remove(node.id);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String,Node> hmBuiltNodes = new HashMap<String,Node>();
|
private HashMap<String,Node> hmBuiltNodes = new HashMap<String,Node>();
|
||||||
|
|
|
@ -149,4 +149,8 @@ public interface TorServiceConstants {
|
||||||
//DNS daemon for TCP DNS over TOr
|
//DNS daemon for TCP DNS over TOr
|
||||||
public final static String PDNSD_ASSET_KEY = "pdnsd";
|
public final static String PDNSD_ASSET_KEY = "pdnsd";
|
||||||
|
|
||||||
|
//EXIT COUNTRY CODES
|
||||||
|
public final static String[] COUNTRY_CODES = {"DE","AT","SE","CH","IS","CA","US","FR","BG","AU","BR","CZ","DK","FI","GB","HU","NL","JP","HK","RO","RU","SG","SK","CN"};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue