create a new pref: "Allow Background Starts"

This lets the user disable the new ACTION_START Intent, in case they have
more sensitive needs.
This commit is contained in:
Hans-Christoph Steiner 2015-06-10 18:00:30 -04:00
parent 77b1bdfbc5
commit ac8329c7f2
4 changed files with 17 additions and 1 deletions

View File

@ -126,6 +126,8 @@
<string name="pref_entrance_node">Entrance Nodes</string>
<string name="pref_entrance_node_summary">Fingerprints, nicks, countries and addresses for the first hop</string>
<string name="pref_entrance_node_dialog">Enter Entrance Nodes</string>
<string name="pref_allow_background_starts_title">Allow Background Starts</string>
<string name="pref_allow_background_starts_summary">Let any app tell Orbot to start Tor and related services</string>
<string name="button_proxy_all">Proxy All</string>
<string name="button_proxy_none">Proxy None</string>

View File

@ -22,6 +22,11 @@ android:summary="@string/pref_use_expanded_notifications"
android:enabled="true"
android:title="@string/pref_use_expanded_notifications_title"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_allow_background_starts"
android:summary="@string/pref_allow_background_starts_summary"
android:title="@string/pref_allow_background_starts_title"/>
<ListPreference android:title="@string/set_locale_title"
android:key="pref_default_locale"

View File

@ -16,6 +16,7 @@ public class Prefs {
private final static String PREF_HAS_ROOT = "has_root";
private final static String PREF_PERSIST_NOTIFICATIONS = "pref_persistent_notifications";
private final static String PREF_START_ON_BOOT = "pref_start_boot";
private final static String PREF_ALLOW_BACKGROUND_STARTS = "pref_allow_background_starts";
private final static String PREF_TRANSPARENT = "pref_transparent";
private final static String PREF_TRANSPARENT_ALL = "pref_transparent_all";
private final static String PREF_TRANSPARENT_TETHERING = "pref_transparent_tethering";
@ -98,6 +99,10 @@ public class Prefs {
return prefs.getBoolean(PREF_PERSIST_NOTIFICATIONS, true);
}
public static boolean allowBackgroundStarts() {
return prefs.getBoolean(PREF_ALLOW_BACKGROUND_STARTS, true);
}
public static boolean useVpn() {
return prefs.getBoolean(PREF_USE_VPN, false);
}

View File

@ -6,13 +6,17 @@ import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import org.torproject.android.Prefs;
public class StartTorReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
/* sanitize the Intent before forwarding it to TorService */
Prefs.setContext(context);
String action = intent.getAction();
if (TextUtils.equals(action, TorServiceConstants.ACTION_START)) {
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);