[tor-commits] [orbot/master] expose start action via a BroadcastReceiver that any app can send to
n8fr8 at torproject.org
n8fr8 at torproject.org
Thu Jun 25 14:59:59 UTC 2015
commit f433a5e6556c93386c5e018285efe038c83afa8f
Author: Hans-Christoph Steiner <hans at eds.org>
Date: Wed Jun 10 14:46:05 2015 -0400
expose start action via a BroadcastReceiver that any app can send to
This allows any app to broadcast an Intent to Orbot in order to make Orbot
start in the background.
closes #3117 https://dev.guardianproject.info/issues/3117
---
AndroidManifest.xml | 10 +++++++++-
src/org/torproject/android/OrbotMainActivity.java | 10 +++++-----
.../torproject/android/service/OnBootReceiver.java | 4 ++--
.../android/service/StartTorReceiver.java | 20 ++++++++++++++++++++
src/org/torproject/android/service/TorService.java | 2 +-
.../android/service/TorServiceConstants.java | 2 +-
6 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 603ac70..23f5e4e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -87,7 +87,15 @@
android:permission="org.torproject.android.MANAGE_TOR"
android:stopWithTask="false" >
</service>
-
+
+ <receiver
+ android:name=".service.StartTorReceiver"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="org.torproject.android.intent.action.START" />
+ </intent-filter>
+ </receiver>
+
<receiver android:name="org.torproject.android.service.OnBootReceiver"
android:enabled="true" android:exported="true"
diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java
index 38d3a80..bfa777d 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -924,11 +924,11 @@ public class OrbotMainActivity extends Activity
}
}
}
-
- private void requestTorRereadConfig() {
- sendIntentToService (TorServiceConstants.CMD_START);
+
+ private void requestTorRereadConfig() {
+ sendIntentToService(TorServiceConstants.CMD_SIGNAL_HUP);
}
-
+
public void promptStartVpnService ()
{
LayoutInflater li = LayoutInflater.from(this);
@@ -1127,7 +1127,7 @@ public class OrbotMainActivity extends Activity
imgStatus.setImageResource(R.drawable.torstarting);
lblStatus.setText(getString(R.string.status_starting_up));
- sendIntentToService(TorServiceConstants.CMD_START);
+ sendIntentToService(TorServiceConstants.ACTION_START);
//we send a message here to the progressDialog i believe, but we can clarify that shortly
Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE);
diff --git a/src/org/torproject/android/service/OnBootReceiver.java b/src/org/torproject/android/service/OnBootReceiver.java
index 49c4ab8..2429c4d 100644
--- a/src/org/torproject/android/service/OnBootReceiver.java
+++ b/src/org/torproject/android/service/OnBootReceiver.java
@@ -16,8 +16,8 @@ public class OnBootReceiver extends BroadcastReceiver {
Prefs.setContext(context);
if (Prefs.startOnBoot())
{
- startService(TorServiceConstants.CMD_START,context);
-
+ startService(TorServiceConstants.ACTION_START, context);
+
if (Prefs.useVpn())
startVpnService(context);
}
diff --git a/src/org/torproject/android/service/StartTorReceiver.java b/src/org/torproject/android/service/StartTorReceiver.java
new file mode 100644
index 0000000..c236484
--- /dev/null
+++ b/src/org/torproject/android/service/StartTorReceiver.java
@@ -0,0 +1,20 @@
+
+package org.torproject.android.service;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.text.TextUtils;
+
+public class StartTorReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ /* sanitize the Intent before forwarding it to TorService */
+ if (TextUtils.equals(intent.getAction(), TorServiceConstants.ACTION_START)) {
+ Intent startTorService = new Intent(context, TorService.class);
+ startTorService.setAction(intent.getAction());
+ context.startService(startTorService);
+ }
+ }
+}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 089e2c6..efde5c6 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -341,7 +341,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
String action = mIntent.getAction();
if (action != null) {
- if (action.equals(CMD_START)) {
+ if (action.equals(ACTION_START)) {
startTor();
// stopTor() is called when the Service is destroyed
} else if (action.equals(CMD_SIGNAL_HUP)) {
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index c31a670..96715b6 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -67,6 +67,7 @@ public interface TorServiceConstants {
//control port
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
+ public final static String ACTION_START = "org.torproject.android.intent.action.START";
public final static String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
@@ -79,7 +80,6 @@ public interface TorServiceConstants {
public final static String STATUS_STARTING = "STARTING";
public final static String STATUS_STOPPING = "STOPPING";
- public static final String CMD_START = "start";
public static final String CMD_SIGNAL_HUP = "signal_hup";
public static final String CMD_FLUSH = "flush";
public static final String CMD_NEWNYM = "newnym";
More information about the tor-commits
mailing list