From b620f828a1a86875bf93fa3291c7a753d02070fd Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 11 Jun 2015 17:02:56 -0400 Subject: [PATCH] include dynamic proxy config info in ACTION_STATUS replies This includes extras in the Intents that are sent as replies to the two different requests to start tor (ACTION_START and ACTION_START_TOR). These extras give all of the current SOCKS and HTTP proxy settings, so that the app can dynamically use the correct settings. Sometimes there are port conflicts, so apps should dynamically adjust in order to reliably find tor. closes #3612 https://dev.guardianproject.info/issues/3612 refs #4419 https://dev.guardianproject.info/issues/4419 refs #3690 https://dev.guardianproject.info/issues/3690 refs #3687 https://dev.guardianproject.info/issues/3687 refs #3859 https://dev.guardianproject.info/issues/3859 --- .../torproject/android/OrbotMainActivity.java | 35 +++++++++---------- .../android/service/TorService.java | 6 ++++ .../android/service/TorServiceConstants.java | 12 +++++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index 978d8ccf..b1635f28 100644 --- a/src/org/torproject/android/OrbotMainActivity.java +++ b/src/org/torproject/android/OrbotMainActivity.java @@ -85,7 +85,8 @@ public class OrbotMainActivity extends Activity /* Some tracking bits */ private String torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service - + private Intent lastStatusIntent; // the last ACTION_STATUS Intent received + private SharedPreferences mPrefs = null; private boolean autoStartFromIntent = false; @@ -164,6 +165,7 @@ public class OrbotMainActivity extends Activity mStatusUpdateHandler.sendMessage(msg); } else if (action.equals(TorServiceConstants.ACTION_STATUS)) { + lastStatusIntent = intent; torStatus = intent.getStringExtra(TorServiceConstants.EXTRA_STATUS); Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE); msg.obj = ""; @@ -554,24 +556,21 @@ public class OrbotMainActivity extends Activity else if (action.equals("org.torproject.android.START_TOR")) { autoStartFromIntent = true; - try { - Log.i(TAG, "action equals org.torproject.android.START_TOR"); - startTor(); - - Intent resultIntent = new Intent(intent); - resultIntent.putExtra("socks_proxy", "socks://127.0.0.1:" + TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT); - resultIntent.putExtra("socks_proxy_host", "127.0.0.1"); - resultIntent.putExtra("socks_proxy_port", TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT); - resultIntent.putExtra("http_proxy", "http://127.0.0.1" + TorServiceConstants.HTTP_PROXY_PORT_DEFAULT); - resultIntent.putExtra("http_proxy_host", "127.0.0.1"); - resultIntent.putExtra("http_proxy_port", TorServiceConstants.HTTP_PROXY_PORT_DEFAULT); - setResult(RESULT_OK, resultIntent); - finish(); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + try { + startTor(); + Intent resultIntent; + if (lastStatusIntent == null) { + resultIntent = new Intent(intent); + } else { + resultIntent = lastStatusIntent; + } + resultIntent.putExtra(TorServiceConstants.EXTRA_STATUS, torStatus); + setResult(RESULT_OK, resultIntent); + finish(); + } catch (RemoteException e) { + e.printStackTrace(); + } } else if (action.equals(Intent.ACTION_VIEW)) { diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 46b55ae9..7e057a0a 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -762,6 +762,12 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon } Intent reply = new Intent(ACTION_STATUS); reply.putExtra(EXTRA_STATUS, mCurrentStatus); + reply.putExtra(EXTRA_SOCKS_PROXY, "socks://127.0.0.1:" + mPortSOCKS); + reply.putExtra(EXTRA_SOCKS_PROXY_HOST, "127.0.0.1"); + reply.putExtra(EXTRA_SOCKS_PROXY_PORT, mPortSOCKS); + reply.putExtra(EXTRA_HTTP_PROXY, "http://127.0.0.1" + mPortHTTP); + reply.putExtra(EXTRA_HTTP_PROXY_HOST, "127.0.0.1"); + reply.putExtra(EXTRA_HTTP_PROXY_PORT, mPortHTTP); reply.setPackage(packageName); sendBroadcast(reply); } diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index a0aed24d..adaa6740 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -84,6 +84,18 @@ public interface TorServiceConstants { * to, used in {@link #ACTION_START} {@link Intent}s sent to Orbot */ public final static String EXTRA_PACKAGE_NAME = "org.torproject.android.intent.extra.PACKAGE_NAME"; + /** + * The SOCKS proxy settings in URL form. + */ + public final static String EXTRA_SOCKS_PROXY = "org.torproject.android.intent.extra.SOCKS_PROXY"; + public final static String EXTRA_SOCKS_PROXY_HOST = "org.torproject.android.intent.extra.SOCKS_PROXY_HOST"; + public final static String EXTRA_SOCKS_PROXY_PORT = "org.torproject.android.intent.extra.SOCKS_PROXY_PORT"; + /** + * The HTTP proxy settings in URL form. + */ + public final static String EXTRA_HTTP_PROXY = "org.torproject.android.intent.extra.HTTP_PROXY"; + public final static String EXTRA_HTTP_PROXY_HOST = "org.torproject.android.intent.extra.HTTP_PROXY_HOST"; + public final static String EXTRA_HTTP_PROXY_PORT = "org.torproject.android.intent.extra.HTTP_PROXY_PORT"; public final static String LOCAL_ACTION_LOG = "log"; public final static String LOCAL_ACTION_BANDWIDTH = "bandwidth";