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.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
|
@ -306,38 +307,46 @@ 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);
|
||||
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);
|
||||
|
||||
|
||||
if (selIdx != -1)
|
||||
spnCountries.setSelection(selIdx);
|
||||
|
||||
spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
|
||||
// your code here
|
||||
|
||||
String country = (String)spnCountries.getItemAtPosition(position);
|
||||
String country = null;
|
||||
|
||||
if (position == 0)
|
||||
country = "";
|
||||
else
|
||||
country = '{' + country.toLowerCase() + '}';
|
||||
country = '{' + TorServiceConstants.COUNTRY_CODES[position-1] + '}';
|
||||
|
||||
Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
|
||||
torService.setAction(TorServiceConstants.CMD_SET_EXIT);
|
||||
torService.putExtra("exit",country);
|
||||
startService(torService);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.torproject.android;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -23,7 +25,8 @@ public class Prefs {
|
|||
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_VPN = "pref_vpn";
|
||||
|
||||
private final static String PREF_EXIT_NODES = "pref_exit_nodes";
|
||||
|
||||
private static SharedPreferences prefs;
|
||||
|
||||
public static void setContext(Context context) {
|
||||
|
@ -118,4 +121,14 @@ public class Prefs {
|
|||
public static void putStartOnBoot(boolean 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,71 +1414,71 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
if (mCurrentStatus == STATUS_STARTING && TextUtils.equals(status, "BUILT"))
|
||||
sendCallbackStatus(STATUS_ON);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Circuit (");
|
||||
sb.append((circID));
|
||||
sb.append(") ");
|
||||
sb.append(status);
|
||||
sb.append(": ");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Circuit (");
|
||||
sb.append((circID));
|
||||
sb.append(") ");
|
||||
sb.append(status);
|
||||
sb.append(": ");
|
||||
|
||||
StringTokenizer st = new StringTokenizer(path,",");
|
||||
Node node = null;
|
||||
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String nodePath = st.nextToken();
|
||||
node = new Node();
|
||||
|
||||
StringTokenizer st = new StringTokenizer(path,",");
|
||||
Node node = null;
|
||||
String[] nodeParts;
|
||||
|
||||
while (st.hasMoreTokens())
|
||||
if (nodePath.contains("="))
|
||||
nodeParts = nodePath.split("=");
|
||||
else
|
||||
nodeParts = nodePath.split("~");
|
||||
|
||||
if (nodeParts.length == 1)
|
||||
{
|
||||
String nodePath = st.nextToken();
|
||||
node = new Node();
|
||||
|
||||
String[] nodeParts;
|
||||
|
||||
if (nodePath.contains("="))
|
||||
nodeParts = nodePath.split("=");
|
||||
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 (" > ");
|
||||
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];
|
||||
}
|
||||
|
||||
if (Prefs.useDebugLogging())
|
||||
debug(sb.toString());
|
||||
else if(status.equals("BUILT"))
|
||||
logNotice(sb.toString());
|
||||
else if (status.equals("CLOSED"))
|
||||
logNotice(sb.toString());
|
||||
node.status = status;
|
||||
|
||||
sb.append(node.name);
|
||||
|
||||
if (st.hasMoreTokens())
|
||||
sb.append (" > ");
|
||||
}
|
||||
|
||||
if (Prefs.useDebugLogging())
|
||||
debug(sb.toString());
|
||||
else if(status.equals("BUILT"))
|
||||
logNotice(sb.toString());
|
||||
else if (status.equals("CLOSED"))
|
||||
logNotice(sb.toString());
|
||||
|
||||
if (Prefs.expandedNotifications())
|
||||
{
|
||||
//get IP from last nodename
|
||||
if(status.equals("BUILT")){
|
||||
|
||||
if (node.ipAddress == null)
|
||||
mExecutor.execute(new ExternalIPFetcher(node));
|
||||
|
||||
hmBuiltNodes.put(node.id, node);
|
||||
}
|
||||
if (Prefs.expandedNotifications())
|
||||
{
|
||||
//get IP from last nodename
|
||||
if(status.equals("BUILT")){
|
||||
|
||||
if (status.equals("CLOSED"))
|
||||
{
|
||||
hmBuiltNodes.remove(node.id);
|
||||
|
||||
}
|
||||
if (node.ipAddress == null)
|
||||
mExecutor.execute(new ExternalIPFetcher(node));
|
||||
|
||||
hmBuiltNodes.put(node.id, node);
|
||||
}
|
||||
|
||||
if (status.equals("CLOSED"))
|
||||
{
|
||||
hmBuiltNodes.remove(node.id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -148,5 +148,9 @@ public interface TorServiceConstants {
|
|||
|
||||
//DNS daemon for TCP DNS over TOr
|
||||
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