[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] Check OrbotService status, start Tor, if down, switch to Meek, when started, fetch CAPTCHA, as soon as done with that.
- To: tor-commits@xxxxxxxxxxxxxxxxxxxx
- Subject: [tor-commits] [orbot/master] Check OrbotService status, start Tor, if down, switch to Meek, when started, fetch CAPTCHA, as soon as done with that.
- From: n8fr8@xxxxxxxxxxxxxx
- Date: Tue, 28 Apr 2020 21:05:02 +0000 (UTC)
- Delivered-to: archiver@xxxxxxxx
- Delivery-date: Tue, 28 Apr 2020 17:10:51 -0400
- List-archive: <http://lists.torproject.org/pipermail/tor-commits/>
- List-help: <mailto:tor-commits-request@lists.torproject.org?subject=help>
- List-id: "auto: code repository commits" <tor-commits.lists.torproject.org>
- List-post: <mailto:tor-commits@lists.torproject.org>
- List-subscribe: <https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits>, <mailto:tor-commits-request@lists.torproject.org?subject=subscribe>
- List-unsubscribe: <https://lists.torproject.org/cgi-bin/mailman/options/tor-commits>, <mailto:tor-commits-request@lists.torproject.org?subject=unsubscribe>
- Patch-author: Benjamin Erhart <berhart@xxxxxxxxxxxxxxxxxxx>
- Sender: "tor-commits" <tor-commits-bounces@xxxxxxxxxxxxxxxxxxxx>
commit c026e2064389725a4c5b66ee801e667ff5400ca3
Author: Benjamin Erhart <berhart@xxxxxxxxxxxxxxxxxxx>
Date: Fri Apr 17 17:16:36 2020 +0200
Check OrbotService status, start Tor, if down, switch to Meek, when started, fetch CAPTCHA, as soon as done with that.
Proxy Volley correctly.
Improved option menu handling.
Not working, yet: Tor doesn't come up. Why?
---
.../org/torproject/android/OrbotMainActivity.java | 5 +-
.../android/ui/onboarding/MoatActivity.java | 120 ++++++++++++++++++---
.../android/ui/onboarding/ProxiedHurlStack.java | 33 ++++++
3 files changed, 141 insertions(+), 17 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index ff23beed..d21e1d05 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -209,11 +209,9 @@ public class OrbotMainActivity extends AppCompatActivity
}
private void sendIntentToService(final String action) {
-
Intent intent = new Intent(OrbotMainActivity.this, OrbotService.class);
intent.setAction(action);
startService(intent);
-
}
private void stopTor() {
@@ -930,6 +928,7 @@ public class OrbotMainActivity extends AppCompatActivity
if (mBtnBridges.isChecked()) {
Prefs.putBridgesEnabled(true);
+
startActivity(new Intent(this, BridgeWizardActivity.class));
} else {
enableBridges(false);
@@ -1200,8 +1199,8 @@ public class OrbotMainActivity extends AppCompatActivity
@Override
protected void onDestroy() {
super.onDestroy();
- LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver);
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver);
}
public static class DataCount {
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 e5ea5459..e2f642fd 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
@@ -1,9 +1,16 @@
+/* Copyright (c) 2020, Benjamin Erhart, Orbot / The Guardian Project - https://guardianproject.info */
+/* See LICENSE for licensing information */
package org.torproject.android.ui.onboarding;
import android.app.Dialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
@@ -16,6 +23,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
@@ -28,6 +36,8 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.torproject.android.R;
+import org.torproject.android.service.OrbotService;
+import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
/**
@@ -51,6 +61,31 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
private RequestQueue mQueue;
+ private String mTorStatus;
+
+ private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String host = intent.getStringExtra(OrbotService.EXTRA_SOCKS_PROXY_HOST);
+ int port = intent.getIntExtra(OrbotService.EXTRA_SOCKS_PROXY_PORT,-1);
+ String status = intent.getStringExtra(TorServiceConstants.EXTRA_STATUS);
+
+ if (TextUtils.isEmpty(host)) {
+ host = TorServiceConstants.IP_LOCALHOST;
+ }
+
+ if (port < 1) {
+ port = Integer.parseInt(TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT);
+ }
+
+ if (TextUtils.isEmpty(status)) {
+ status = TorServiceConstants.STATUS_OFF;
+ }
+
+ setUp(host, port, status);
+ }
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -72,7 +107,8 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
findViewById(R.id.requestBt).setOnClickListener(this);
- mQueue = Volley.newRequestQueue(this);
+ LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver,
+ new IntentFilter(TorServiceConstants.ACTION_STATUS));
}
@Override
@@ -85,32 +121,51 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
}
@Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ menu.findItem(R.id.menu_refresh)
+ .setEnabled(TorServiceConstants.STATUS_ON.equals(mTorStatus));
+
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
protected void onResume() {
super.onResume();
- // Set to Meek bridge.
- Prefs.setBridgesList("meek");
- Prefs.putBridgesEnabled(true);
-
- fetchCaptcha();
+ sendIntentToService(TorServiceConstants.ACTION_STATUS);
}
@Override
public void onClick(View view) {
- Log.d(MoatActivity.class.toString(), "Request Bridge!");
+ Log.d(MoatActivity.class.getSimpleName(), "Request Bridge!");
requestBridges(mSolutionEt.getText().toString());
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.menu_refresh) {
- fetchCaptcha();
+ switch (item.getItemId()) {
+ case R.id.menu_refresh:
+ fetchCaptcha();
+
+ return true;
+
+ case android.R.id.home:
+ finish();
+
+ return true;
}
return super.onOptionsItemSelected(item);
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
+ }
+
private void fetchCaptcha() {
JsonObjectRequest request = buildRequest("fetch",
"\"type\": \"client-transports\", \"supported\": [\"obfs4\"]",
@@ -125,7 +180,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
mCaptchaIv.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length));
} catch (JSONException e) {
- Log.d(MoatActivity.class.toString(), "Error decoding answer.");
+ Log.d(MoatActivity.class.getSimpleName(), "Error decoding answer.");
new AlertDialog.Builder(MoatActivity.this)
.setTitle(R.string.error)
@@ -156,7 +211,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
try {
JSONArray bridges = response.getJSONArray("data").getJSONObject(0).getJSONArray("bridges");
- Log.d(MoatActivity.class.toString(), "Bridges: " + bridges.toString());
+ Log.d(MoatActivity.class.getSimpleName(), "Bridges: " + bridges.toString());
StringBuilder sb = new StringBuilder();
@@ -170,7 +225,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
MoatActivity.this.finish();
} catch (JSONException e) {
- Log.d(MoatActivity.class.toString(), "Error decoding answer: " + response.toString());
+ Log.d(MoatActivity.class.getSimpleName(), "Error decoding answer: " + response.toString());
new AlertDialog.Builder(MoatActivity.this)
.setTitle(R.string.error)
@@ -200,7 +255,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
return null;
}
- Log.d(MoatActivity.class.toString(), "Request: " + requestBody.toString());
+ Log.d(MoatActivity.class.getSimpleName(), "Request: " + requestBody.toString());
return new JsonObjectRequest(
Request.Method.POST,
@@ -210,7 +265,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
- Log.d(MoatActivity.class.toString(), "Error response.");
+ Log.d(MoatActivity.class.getSimpleName(), "Error response.");
new AlertDialog.Builder(MoatActivity.this)
.setTitle(R.string.error)
@@ -230,4 +285,41 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
}
};
}
+
+ private void sendIntentToService(final String action) {
+ Intent intent = new Intent(this, OrbotService.class);
+ intent.setAction(action);
+ startService(intent);
+ }
+
+ private void setUp(String host, int port, String status) {
+ Log.d(MoatActivity.class.getSimpleName(), "Tor status=" + status);
+
+ mTorStatus = status;
+ invalidateOptionsMenu();
+
+ switch (status) {
+ case TorServiceConstants.STATUS_OFF:
+ sendIntentToService(TorServiceConstants.ACTION_START);
+
+ break;
+
+ case TorServiceConstants.STATUS_ON:
+ Prefs.setBridgesList("moat");
+ Prefs.putBridgesEnabled(true);
+
+ Log.d(MoatActivity.class.getSimpleName(), "Set up Volley queue. host=" + host + ", port=" + port);
+
+ mQueue = Volley.newRequestQueue(MoatActivity.this, new ProxiedHurlStack(host, port));
+
+ sendIntentToService(TorServiceConstants.CMD_SIGNAL_HUP);
+
+ fetchCaptcha();
+
+ break;
+
+ default:
+ sendIntentToService(TorServiceConstants.ACTION_STATUS);
+ }
+ }
}
diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/ProxiedHurlStack.java b/app/src/main/java/org/torproject/android/ui/onboarding/ProxiedHurlStack.java
new file mode 100644
index 00000000..e3bdb86a
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/ui/onboarding/ProxiedHurlStack.java
@@ -0,0 +1,33 @@
+/* Copyright (c) 2020, Benjamin Erhart, Orbot / The Guardian Project - https://guardianproject.info */
+/* See LICENSE for licensing information */
+package org.torproject.android.ui.onboarding;
+
+import com.android.volley.toolbox.HurlStack;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+
+@SuppressWarnings("WeakerAccess")
+public class ProxiedHurlStack extends HurlStack {
+
+ private final String mHost;
+ private final int mPort;
+
+ public ProxiedHurlStack(String host, int port) {
+ super();
+
+ mHost = host;
+ mPort = port;
+ }
+
+ @Override
+ protected HttpURLConnection createConnection(URL url) throws IOException {
+ Proxy proxy = new Proxy(Proxy.Type.SOCKS,
+ InetSocketAddress.createUnresolved(mHost, mPort));
+
+ return (HttpURLConnection) url.openConnection(proxy);
+ }
+}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits