let the requesting app know that the user has disabled starting via Intent

If an app is using ACTION_START to start Orbot in the background, but the
user had disabled that using the allowBackgroundStarts pref, then the app
will want to know about that so it can fallback on prompting the user to
bring up Orbot itself for the user to manually start it.

refs #3117 https://dev.guardianproject.info/issues/3117
This commit is contained in:
Hans-Christoph Steiner 2015-06-10 18:15:29 -04:00
parent ac8329c7f2
commit 775135d07a
2 changed files with 23 additions and 11 deletions

View File

@ -8,21 +8,29 @@ import android.text.TextUtils;
import org.torproject.android.Prefs; import org.torproject.android.Prefs;
public class StartTorReceiver extends BroadcastReceiver { public class StartTorReceiver extends BroadcastReceiver implements TorServiceConstants {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
/* sanitize the Intent before forwarding it to TorService */ /* sanitize the Intent before forwarding it to TorService */
Prefs.setContext(context); Prefs.setContext(context);
String action = intent.getAction(); String action = intent.getAction();
if (Prefs.allowBackgroundStarts() if (TextUtils.equals(action, ACTION_START)) {
&& TextUtils.equals(action, TorServiceConstants.ACTION_START)) { String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
Intent startTorIntent = new Intent(context, TorService.class); if (Prefs.allowBackgroundStarts()) {
startTorIntent.setAction(action); Intent startTorIntent = new Intent(context, TorService.class);
String packageName = intent.getStringExtra(TorServiceConstants.EXTRA_PACKAGE_NAME); startTorIntent.setAction(action);
if (packageName != null) if (packageName != null)
startTorIntent.putExtra(TorServiceConstants.EXTRA_PACKAGE_NAME, packageName); startTorIntent.putExtra(EXTRA_PACKAGE_NAME, packageName);
context.startService(startTorIntent); 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);
}
} }
} }
} }

View File

@ -104,6 +104,11 @@ public interface TorServiceConstants {
public final static String STATUS_ON = "ON"; public final static String STATUS_ON = "ON";
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";
/**
* 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 // actions for internal command Intents
public static final String CMD_SIGNAL_HUP = "signal_hup"; public static final String CMD_SIGNAL_HUP = "signal_hup";
@ -113,7 +118,6 @@ public interface TorServiceConstants {
public static final String CMD_VPN_CLEAR = "vpnclear"; public static final String CMD_VPN_CLEAR = "vpnclear";
public static final String CMD_UPDATE_TRANS_PROXY = "update"; public static final String CMD_UPDATE_TRANS_PROXY = "update";
public static final String BINARY_TOR_VERSION = "0.2.6.7"; public static final String BINARY_TOR_VERSION = "0.2.6.7";
public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED"; public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";