[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] add bridge wizard testing code
commit df37b8c4a98455c4ac42fb52a6089997fdaa6c0d
Author: n8fr8 <nathan@xxxxxxxxxxx>
Date: Wed Jan 3 12:49:11 2018 -0500
add bridge wizard testing code
---
.../ui/onboarding/BridgeWizardActivity.java | 91 ++++++++++++++++++++++
app/src/main/res/layout/content_bridge_wizard.xml | 34 +++++---
app/src/main/res/values/strings.xml | 5 +-
3 files changed, 117 insertions(+), 13 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java
index 63a7e072..40b7177c 100644
--- a/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java
@@ -7,11 +7,13 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
@@ -22,8 +24,15 @@ import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+
public class BridgeWizardActivity extends AppCompatActivity {
+ private TextView tvStatus;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -32,6 +41,9 @@ public class BridgeWizardActivity extends AppCompatActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ tvStatus = (TextView)findViewById(R.id.lbl_bridge_test_status);
+ tvStatus.setVisibility(View.GONE);
+
setTitle(getString(R.string.bridges));
findViewById(R.id.btnBridgesDirect).setOnClickListener(new View.OnClickListener() {
@@ -39,6 +51,8 @@ public class BridgeWizardActivity extends AppCompatActivity {
public void onClick(View v) {
Prefs.setBridgesList("");
Prefs.putBridgesEnabled(false);
+ testBridgeConnection();
+
}
});
@@ -47,6 +61,8 @@ public class BridgeWizardActivity extends AppCompatActivity {
public void onClick(View v) {
Prefs.setBridgesList("obfs4");
Prefs.putBridgesEnabled(true);
+ testBridgeConnection();
+
}
});
@@ -56,6 +72,8 @@ public class BridgeWizardActivity extends AppCompatActivity {
public void onClick(View v) {
Prefs.setBridgesList("meek");
Prefs.putBridgesEnabled(true);
+ testBridgeConnection();
+
}
});
@@ -213,4 +231,77 @@ public class BridgeWizardActivity extends AppCompatActivity {
}
}
+ private void testBridgeConnection ()
+ {
+ if (TextUtils.isEmpty(Prefs.getBridgesList()) || (!Prefs.bridgesEnabled()))
+ {
+ new HostTester().execute("check.torproject.org","443");
+ }
+ else if (Prefs.getBridgesList().equals("meek"))
+ {
+ new HostTester().execute("meek.azureedge.net","443","d2cly7j4zqgua7.cloudfront.net","443");
+ }
+ else if (Prefs.getBridgesList().equals("obfs4"))
+ {
+ new HostTester().execute("85.17.30.79","443","154.35.22.9","443","192.99.11.54","443");
+ }
+ else
+ {
+ tvStatus.setText("");
+ }
+ }
+
+ private class HostTester extends AsyncTask<String, Void, Boolean> {
+ protected void onPreExecute() {
+ // Pre Code
+ tvStatus.setVisibility(View.VISIBLE);
+ tvStatus.setText(R.string.testing_bridges);
+ }
+ protected Boolean doInBackground(String... host) {
+ // Background Code
+ boolean result = false;
+
+ for (int i = 0; i < host.length; i++) {
+ String testHost = host[i];
+ i++; //move to the port
+ int testPort = Integer.parseInt(host[i]);
+ result = isHostReachable(testHost, testPort, 5000);
+ if (result)
+ return result;
+ }
+
+ return result;
+ }
+ protected void onPostExecute(Boolean result) {
+ // Post Code
+ if (result)
+ {
+ tvStatus.setText(R.string.testing_bridges_success);
+
+ }
+ else
+ {
+ tvStatus.setText(R.string.testing_bridges_fail);
+
+ }
+ }};
+
+ private static boolean isHostReachable(String serverAddress, int serverTCPport, int timeoutMS){
+ boolean connected = false;
+ Socket socket;
+ try {
+ socket = new Socket();
+ SocketAddress socketAddress = new InetSocketAddress(serverAddress, serverTCPport);
+ socket.connect(socketAddress, timeoutMS);
+ if (socket.isConnected()) {
+ connected = true;
+ socket.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ socket = null;
+ }
+ return connected;
+ }
}
diff --git a/app/src/main/res/layout/content_bridge_wizard.xml b/app/src/main/res/layout/content_bridge_wizard.xml
index fb1473ff..609bcdf4 100644
--- a/app/src/main/res/layout/content_bridge_wizard.xml
+++ b/app/src/main/res/layout/content_bridge_wizard.xml
@@ -26,37 +26,47 @@
<RadioButton
android:id="@+id/btnBridgesDirect"
- android:layout_width="315dp"
- android:layout_height="29dp"
- android:text="Direct connection to Tor"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Connect directly to Tor\n(Best, if you can!)"
android:layout_margin="12dp"
/>
<RadioButton
android:id="@+id/btnBridgesObfs4"
- android:layout_width="315dp"
- android:layout_height="29dp"
- android:text="Connect through community bridges (Obfs4)"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Connect through community bridges\n(Second best option, if it works)"
android:layout_margin="12dp"
/>
<RadioButton
android:id="@+id/btnBridgesMeek"
- android:layout_width="315dp"
- android:layout_height="29dp"
- android:text="Hide traffic through Cloud Services"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Hide traffic through cloud services\n(Slower, but harder to block)"
android:layout_margin="12dp"
/>
<RadioButton
android:id="@+id/btnBridgesNew"
- android:layout_width="315dp"
- android:layout_height="29dp"
- android:text="Request New Bridges..."
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Request New Bridges...\n(If all the other options fail...)"
android:layout_margin="12dp"
/>
</RadioGroup>
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="testing..."
+ android:gravity="center"
+ android:id="@+id/lbl_bridge_test_status"
+ android:layout_margin="12dp"
+ android:textStyle="bold"
+ android:textSize="16sp"
+ />
</LinearLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index cb1a4366..72a226a3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -311,7 +311,7 @@
<string name="menu_qr">QR Codes</string>
- <string name="if_your_mobile_network_actively_blocks_tor_you_can_use_a_tor_bridge_to_access_the_network_another_way_to_get_bridges_is_to_send_an_email_to_bridges_torproject_org_please_note_that_you_must_send_the_email_using_an_address_from_one_of_the_following_email_providers_riseup_gmail_or_yahoo_">If your mobile network actively blocks Tor, you can use a Bridge to access the network. SELECT one of the bridge types above to enable bridges.</string>
+ <string name="if_your_mobile_network_actively_blocks_tor_you_can_use_a_tor_bridge_to_access_the_network_another_way_to_get_bridges_is_to_send_an_email_to_bridges_torproject_org_please_note_that_you_must_send_the_email_using_an_address_from_one_of_the_following_email_providers_riseup_gmail_or_yahoo_">If your mobile network actively blocks Tor, you can use a \'Bridge Server\' as an alternate way in. SELECT one of the options to configure and test..,.</string>
<string name="bridge_mode">Bridge Mode</string>
@@ -391,4 +391,7 @@
<string name="please_enable_vpn">Please activate the VPN mode to enable apps to use Tor</string>
<string name="app_shortcuts">Tor-Enabled Apps</string>
<string name="title_activity_bridge_wizard">BridgeWizardActivity</string>
+ <string name="testing_bridges">Testing bridge connection to Tor....</string>
+ <string name="testing_bridges_success">Success. Bridge configuration is good!</string>
+ <string name="testing_bridges_fail">FAILED. Try another option</string>
</resources>
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits