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
This commit is contained in:
Hans-Christoph Steiner 2015-06-10 14:46:05 -04:00
parent 13d29878f9
commit f433a5e655
6 changed files with 38 additions and 10 deletions

View File

@ -88,6 +88,14 @@
android:stopWithTask="false" > android:stopWithTask="false" >
</service> </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" <receiver android:name="org.torproject.android.service.OnBootReceiver"
android:enabled="true" android:exported="true" android:enabled="true" android:exported="true"

View File

@ -925,8 +925,8 @@ public class OrbotMainActivity extends Activity
} }
} }
private void requestTorRereadConfig() { private void requestTorRereadConfig() {
sendIntentToService (TorServiceConstants.CMD_START); sendIntentToService(TorServiceConstants.CMD_SIGNAL_HUP);
} }
public void promptStartVpnService () public void promptStartVpnService ()
@ -1127,7 +1127,7 @@ public class OrbotMainActivity extends Activity
imgStatus.setImageResource(R.drawable.torstarting); imgStatus.setImageResource(R.drawable.torstarting);
lblStatus.setText(getString(R.string.status_starting_up)); 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 //we send a message here to the progressDialog i believe, but we can clarify that shortly
Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE); Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE);

View File

@ -16,7 +16,7 @@ public class OnBootReceiver extends BroadcastReceiver {
Prefs.setContext(context); Prefs.setContext(context);
if (Prefs.startOnBoot()) if (Prefs.startOnBoot())
{ {
startService(TorServiceConstants.CMD_START,context); startService(TorServiceConstants.ACTION_START, context);
if (Prefs.useVpn()) if (Prefs.useVpn())
startVpnService(context); startVpnService(context);

View File

@ -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);
}
}
}

View File

@ -341,7 +341,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
String action = mIntent.getAction(); String action = mIntent.getAction();
if (action != null) { if (action != null) {
if (action.equals(CMD_START)) { if (action.equals(ACTION_START)) {
startTor(); startTor();
// stopTor() is called when the Service is destroyed // stopTor() is called when the Service is destroyed
} else if (action.equals(CMD_SIGNAL_HUP)) { } else if (action.equals(CMD_SIGNAL_HUP)) {

View File

@ -67,6 +67,7 @@ public interface TorServiceConstants {
//control port //control port
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%"; 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 ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.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_STARTING = "STARTING";
public final static String STATUS_STOPPING = "STOPPING"; 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_SIGNAL_HUP = "signal_hup";
public static final String CMD_FLUSH = "flush"; public static final String CMD_FLUSH = "flush";
public static final String CMD_NEWNYM = "newnym"; public static final String CMD_NEWNYM = "newnym";