[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] handle phantom selection of country exit
commit af1d9337586e218c7791fc4e9a26fd64ab0891cd
Author: n8fr8 <nathan@xxxxxxxxxxx>
Date: Fri May 11 23:24:21 2018 -0400
handle phantom selection of country exit
- also support custom exit override issue
---
.../org/torproject/android/OrbotMainActivity.java | 118 +++++++++++++--------
1 file changed, 71 insertions(+), 47 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 6fc5c456..e3fd1a40 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -360,57 +360,79 @@ public class OrbotMainActivity extends AppCompatActivity
});
- String currentExit = Prefs.getExitNodes();
- int selIdx = -1;
-
- ArrayList<String> cList = new ArrayList<String>();
- cList.add(0, getString(R.string.vpn_default_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, 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 = null;
-
- if (position == 0)
- country = "";
- else
- 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
- public void onNothingSelected(AdapterView<?> parentView) {
- // your code here
- }
+ spnCountries = (Spinner)findViewById(R.id.spinnerCountry);
+ setCountrySpinner();
- });
+ mPulsator = (PulsatorLayout) findViewById(R.id.pulsator);
+ }
- mPulsator = (PulsatorLayout) findViewById(R.id.pulsator);
+ boolean firstTimeCountrySelect = true;
+
+ private void setCountrySpinner ()
+ {
+ String currentExit = Prefs.getExitNodes();
+ if (currentExit.length() > 4)
+ {
+ //someone put a complex value in, so let's disable
+ ArrayList<String> cList = new ArrayList<String>();
+ cList.add(0, currentExit);
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cList);
+ spnCountries.setAdapter(adapter);
+
+ spnCountries.setEnabled(false);
+ }
+ else {
+ int selIdx = -1;
+
+ ArrayList<String> cList = new ArrayList<String>();
+ cList.add(0, getString(R.string.vpn_default_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;
+ }
+
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cList);
+ spnCountries.setAdapter(adapter);
+
+ if (selIdx > 0)
+ spnCountries.setSelection(selIdx,true);
+
+ spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
+ // your code here
+
+ if (firstTimeCountrySelect) {
+ firstTimeCountrySelect = false;
+ return;
+ }
+
+ String country = null;
+
+ if (position == 0)
+ country = "";
+ else
+ 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
+ public void onNothingSelected(AdapterView<?> parentView) {
+ // your code here
+ }
+
+ });
+ }
}
@Override
@@ -1026,6 +1048,8 @@ public class OrbotMainActivity extends AppCompatActivity
mBtnBridges.setChecked(Prefs.bridgesEnabled());
mBtnVPN.setChecked(Prefs.useVpn());
+ setCountrySpinner();
+
requestTorStatus();
if (torStatus == null)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits