[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] allow country exit node select to persist
commit 3b413657086b0ca013f418833e41534970652990
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date: Thu Jan 7 00:59:34 2016 -0500
allow country exit node select to persist
---
src/org/torproject/android/OrbotMainActivity.java | 35 ++++---
src/org/torproject/android/Prefs.java | 15 ++-
src/org/torproject/android/service/TorService.java | 110 ++++++++++----------
.../android/service/TorServiceConstants.java | 4 +
4 files changed, 95 insertions(+), 69 deletions(-)
diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java
index a2e5a60..e93cdd7 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -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
diff --git a/src/org/torproject/android/Prefs.java b/src/org/torproject/android/Prefs.java
index fad04ba..d79f160 100644
--- a/src/org/torproject/android/Prefs.java
+++ b/src/org/torproject/android/Prefs.java
@@ -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);
+ }
}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 24f5965..a1c0bfe 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -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;
+ 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())
+ 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")){
- sb.append(node.name);
+ if (node.ipAddress == null)
+ mExecutor.execute(new ExternalIPFetcher(node));
- if (st.hasMoreTokens())
- 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 (Prefs.expandedNotifications())
+ if (status.equals("CLOSED"))
{
- //get IP from last nodename
- if(status.equals("BUILT")){
-
- if (node.ipAddress == null)
- mExecutor.execute(new ExternalIPFetcher(node));
-
- hmBuiltNodes.put(node.id, node);
- }
+ hmBuiltNodes.remove(node.id);
- if (status.equals("CLOSED"))
- {
- hmBuiltNodes.remove(node.id);
-
- }
}
+ }
}
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index c9bb6ec..2e2002d 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -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"};
+
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits