diff --git a/src/org/torproject/android/service/StartTorReceiver.java b/src/org/torproject/android/service/StartTorReceiver.java index c89d8808..087b01f4 100644 --- a/src/org/torproject/android/service/StartTorReceiver.java +++ b/src/org/torproject/android/service/StartTorReceiver.java @@ -8,21 +8,29 @@ import android.text.TextUtils; import org.torproject.android.Prefs; -public class StartTorReceiver extends BroadcastReceiver { +public class StartTorReceiver extends BroadcastReceiver implements TorServiceConstants { @Override public void onReceive(Context context, Intent intent) { /* sanitize the Intent before forwarding it to TorService */ Prefs.setContext(context); String action = intent.getAction(); - if (Prefs.allowBackgroundStarts() - && TextUtils.equals(action, TorServiceConstants.ACTION_START)) { - Intent startTorIntent = new Intent(context, TorService.class); - startTorIntent.setAction(action); - String packageName = intent.getStringExtra(TorServiceConstants.EXTRA_PACKAGE_NAME); - if (packageName != null) - startTorIntent.putExtra(TorServiceConstants.EXTRA_PACKAGE_NAME, packageName); - context.startService(startTorIntent); + if (TextUtils.equals(action, ACTION_START)) { + String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); + if (Prefs.allowBackgroundStarts()) { + Intent startTorIntent = new Intent(context, TorService.class); + startTorIntent.setAction(action); + if (packageName != null) + startTorIntent.putExtra(EXTRA_PACKAGE_NAME, packageName); + context.startService(startTorIntent); + } else if (!TextUtils.isEmpty(packageName)) { + // let the requesting app know that the user has disabled + // starting via Intent + Intent startsDisabledIntent = new Intent(ACTION_STATUS); + startsDisabledIntent.putExtra(EXTRA_STATUS, STATUS_STARTS_DISABLED); + startsDisabledIntent.setPackage(packageName); + context.sendBroadcast(startsDisabledIntent); + } } } } diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index 7921ddcc..80b37f8d 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -104,6 +104,11 @@ public interface TorServiceConstants { public final static String STATUS_ON = "ON"; public final static String STATUS_STARTING = "STARTING"; public final static String STATUS_STOPPING = "STOPPING"; + /** + * The user has disabled the ability for background starts triggered by + * apps. Fallback to the old Intent that brings up Orbot. + */ + public final static String STATUS_STARTS_DISABLED = "STARTS_DISABLED"; // actions for internal command Intents public static final String CMD_SIGNAL_HUP = "signal_hup"; @@ -112,8 +117,7 @@ public interface TorServiceConstants { public static final String CMD_VPN = "vpn"; public static final String CMD_VPN_CLEAR = "vpnclear"; public static final String CMD_UPDATE_TRANS_PROXY = "update"; - - + public static final String BINARY_TOR_VERSION = "0.2.6.7"; public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";