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:
parent
13d29878f9
commit
f433a5e655
|
@ -88,6 +88,14 @@
|
|||
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"
|
||||
|
||||
|
|
|
@ -925,8 +925,8 @@ public class OrbotMainActivity extends Activity
|
|||
}
|
||||
}
|
||||
|
||||
private void requestTorRereadConfig() {
|
||||
sendIntentToService (TorServiceConstants.CMD_START);
|
||||
private void requestTorRereadConfig() {
|
||||
sendIntentToService(TorServiceConstants.CMD_SIGNAL_HUP);
|
||||
}
|
||||
|
||||
public void promptStartVpnService ()
|
||||
|
@ -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);
|
||||
|
|
|
@ -16,7 +16,7 @@ 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)) {
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue