[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] Fixed MoatActivity startup when Tor is not running. Reset old bridge configuration, when not completed.



commit 964c3115a9eeba7a9d26091ffb49441872b491eb
Author: Benjamin Erhart <berhart@xxxxxxxxxxxxxxxxxxx>
Date:   Wed Apr 22 12:23:18 2020 +0200

    Fixed MoatActivity startup when Tor is not running. Reset old bridge configuration, when not completed.
---
 .../ui/onboarding/BridgeWizardActivity.java        | 79 +++++++++++++++-------
 .../android/ui/onboarding/MoatActivity.java        | 42 ++++++++++--
 2 files changed, 89 insertions(+), 32 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 21b4f4e5..6b439468 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
@@ -34,7 +34,13 @@ public class BridgeWizardActivity extends AppCompatActivity {
 
     private static int MOAT_REQUEST_CODE = 666;
 
-    private TextView tvStatus;
+    private TextView mTvStatus;
+    private RadioButton mBtDirect;
+    private RadioButton mBtObfs4;
+    private RadioButton mBtMeek;
+    private RadioButton mBtNew;
+    private RadioButton mBtMoat;
+
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -48,13 +54,13 @@ public class BridgeWizardActivity extends AppCompatActivity {
             actionBar.setDisplayHomeAsUpEnabled(true);
         }
 
-        tvStatus = findViewById(R.id.lbl_bridge_test_status);
-        tvStatus.setVisibility(View.GONE);
+        mTvStatus = findViewById(R.id.lbl_bridge_test_status);
+        mTvStatus.setVisibility(View.GONE);
 
         setTitle(getString(R.string.bridges));
 
-        RadioButton btnDirect = findViewById(R.id.btnBridgesDirect);
-        btnDirect.setOnClickListener(new View.OnClickListener() {
+        mBtDirect = findViewById(R.id.btnBridgesDirect);
+        mBtDirect.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Prefs.setBridgesList("");
@@ -63,8 +69,8 @@ public class BridgeWizardActivity extends AppCompatActivity {
             }
         });
 
-        RadioButton btnObfs4 = findViewById(R.id.btnBridgesObfs4);
-        btnObfs4.setOnClickListener(new View.OnClickListener() {
+        mBtObfs4 = findViewById(R.id.btnBridgesObfs4);
+        mBtObfs4.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Prefs.setBridgesList("obfs4");
@@ -74,8 +80,8 @@ public class BridgeWizardActivity extends AppCompatActivity {
         });
 
 
-        RadioButton btnMeek = findViewById(R.id.btnBridgesMeek);
-        btnMeek.setOnClickListener(new View.OnClickListener() {
+        mBtMeek = findViewById(R.id.btnBridgesMeek);
+        mBtMeek.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Prefs.setBridgesList("meek");
@@ -85,16 +91,16 @@ public class BridgeWizardActivity extends AppCompatActivity {
         });
 
 
-        RadioButton btnNew = findViewById(R.id.btnBridgesNew);
-        btnNew.setOnClickListener(new View.OnClickListener() {
+        mBtNew = findViewById(R.id.btnBridgesNew);
+        mBtNew.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 showGetBridgePrompt();
             }
         });
 
-        RadioButton btnMoat = findViewById(R.id.btnMoat);
-        btnMoat.setOnClickListener(new View.OnClickListener() {
+        mBtMoat = findViewById(R.id.btnMoat);
+        mBtMoat.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 startActivityForResult(new Intent(BridgeWizardActivity.this, MoatActivity.class),
@@ -102,12 +108,7 @@ public class BridgeWizardActivity extends AppCompatActivity {
             }
         });
 
-        if (!Prefs.bridgesEnabled())
-            btnDirect.setChecked(true);
-        else if (Prefs.getBridgesList().equals("meek"))
-            btnMeek.setChecked(true);
-        else if (Prefs.getBridgesList().equals("obfs4"))
-            btnObfs4.setChecked(true);
+        evaluateBridgeListState();
     }
 
     @Override
@@ -129,8 +130,14 @@ public class BridgeWizardActivity extends AppCompatActivity {
     protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
         // If the MoatActivity could successfully gather OBFS4 bridges,
         // the job is done and we can return immediately.
-        if (requestCode == MOAT_REQUEST_CODE && resultCode == RESULT_OK) {
-            finish();
+        if (requestCode == MOAT_REQUEST_CODE) {
+            if (resultCode == RESULT_OK) {
+                finish();
+            }
+            // Reset selection to actual value.
+            else {
+                evaluateBridgeListState();
+            }
         }
         else {
             super.onActivityResult(requestCode, resultCode, data);
@@ -189,7 +196,7 @@ public class BridgeWizardActivity extends AppCompatActivity {
         } 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("");
+            mTvStatus.setText("");
         }
     }
 
@@ -197,8 +204,8 @@ public class BridgeWizardActivity extends AppCompatActivity {
         @Override
         protected void onPreExecute() {
             // Pre Code
-            tvStatus.setVisibility(View.VISIBLE);
-            tvStatus.setText(R.string.testing_bridges);
+            mTvStatus.setVisibility(View.VISIBLE);
+            mTvStatus.setText(R.string.testing_bridges);
         }
 
         @Override
@@ -221,10 +228,10 @@ public class BridgeWizardActivity extends AppCompatActivity {
         protected void onPostExecute(Boolean result) {
             // Post Code
             if (result) {
-                tvStatus.setText(R.string.testing_bridges_success);
+                mTvStatus.setText(R.string.testing_bridges_success);
 
             } else {
-                tvStatus.setText(R.string.testing_bridges_fail);
+                mTvStatus.setText(R.string.testing_bridges_fail);
 
             }
         }
@@ -249,4 +256,24 @@ public class BridgeWizardActivity extends AppCompatActivity {
 
         return connected;
     }
+
+    private void evaluateBridgeListState() {
+        if (!Prefs.bridgesEnabled()) {
+            mBtDirect.setChecked(true);
+        }
+        else if (Prefs.getBridgesList().equals("meek")) {
+            mBtMeek.setChecked(true);
+        }
+        else if (Prefs.getBridgesList().equals("obfs4")) {
+            mBtObfs4.setChecked(true);
+        }
+        else {
+            mBtDirect.setChecked(false);
+            mBtMeek.setChecked(false);
+            mBtObfs4.setChecked(false);
+        }
+
+        mBtNew.setChecked(false);
+        mBtMoat.setChecked(false);
+    }
 }
diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java
index 464b3bd4..71d97715 100644
--- a/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java
@@ -30,6 +30,7 @@ import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.widget.Toolbar;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
 
+import com.android.volley.DefaultRetryPolicy;
 import com.android.volley.Request;
 import com.android.volley.RequestQueue;
 import com.android.volley.Response;
@@ -68,6 +69,11 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
 
     private RequestQueue mQueue;
 
+    private String mOriginalBridges;
+    private boolean mOriginalBridgeStatus;
+
+    private boolean mSuccess;
+
     private String mTorStatus;
 
     private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@@ -144,6 +150,9 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
     protected void onResume() {
         super.onResume();
 
+        mOriginalBridges = Prefs.getBridgesList();
+        mOriginalBridgeStatus = Prefs.bridgesEnabled();
+
         sendIntentToService(TorServiceConstants.ACTION_STATUS);
     }
 
@@ -193,6 +202,19 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
     }
 
     @Override
+    protected void onPause() {
+        super.onPause();
+
+        if (mSuccess) {
+            setResult(RESULT_OK);
+        }
+        else {
+            Prefs.setBridgesList(mOriginalBridges);
+            Prefs.putBridgesEnabled(mOriginalBridgeStatus);
+        }
+    }
+
+    @Override
     protected void onDestroy() {
         super.onDestroy();
 
@@ -259,7 +281,8 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
 
                             mProgressBar.setVisibility(View.GONE);
 
-                            MoatActivity.this.setResult(RESULT_OK);
+                            mSuccess = true;
+
                             MoatActivity.this.finish();
                         }
                         catch (JSONException e) {
@@ -286,7 +309,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
 
         Log.d(MoatActivity.class.getSimpleName(), "Request: " + requestBody.toString());
 
-        return new JsonObjectRequest(
+        JsonObjectRequest request = new JsonObjectRequest(
                 Request.Method.POST,
                 moatBaseUrl + "/" + endpoint,
                 requestBody,
@@ -304,6 +327,11 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
                 return "application/vnd.api+json";
             }
         };
+
+        request.setRetryPolicy(new DefaultRetryPolicy(30000,
+                3, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
+
+        return request;
     }
 
     private void sendIntentToService(final String action) {
@@ -320,12 +348,17 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
 
         switch (status) {
             case TorServiceConstants.STATUS_OFF:
+                // We need the Meek bridge.
+                Prefs.setBridgesList("meek");
+                Prefs.putBridgesEnabled(true);
+
                 sendIntentToService(TorServiceConstants.ACTION_START);
 
                 break;
 
             case TorServiceConstants.STATUS_ON:
-                Prefs.setBridgesList("moat");
+                // Switch to the Meek bridge, if not done, already.
+                Prefs.setBridgesList("meek");
                 Prefs.putBridgesEnabled(true);
 
                 Log.d(MoatActivity.class.getSimpleName(), "Set up Volley queue. host=" + host + ", port=" + port);
@@ -337,9 +370,6 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
                 fetchCaptcha();
 
                 break;
-
-            default:
-                sendIntentToService(TorServiceConstants.ACTION_STATUS);
         }
     }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits