[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] create a new pref: "Allow Background Starts"



commit ac8329c7f279b1e3afb747cff8b15c2fa1821bf1
Author: Hans-Christoph Steiner <hans@xxxxxxx>
Date:   Wed Jun 10 18:00:30 2015 -0400

    create a new pref: "Allow Background Starts"
    
    This lets the user disable the new ACTION_START Intent, in case they have
    more sensitive needs.
---
 res/values/strings.xml                                   |    2 ++
 res/xml/preferences.xml                                  |    5 +++++
 src/org/torproject/android/Prefs.java                    |    5 +++++
 src/org/torproject/android/service/StartTorReceiver.java |    6 +++++-
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/res/values/strings.xml b/res/values/strings.xml
index 87aa35f..decd892 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -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>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index d910fee..e1e1828 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -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"
diff --git a/src/org/torproject/android/Prefs.java b/src/org/torproject/android/Prefs.java
index b1b1793..fad04ba 100644
--- a/src/org/torproject/android/Prefs.java
+++ b/src/org/torproject/android/Prefs.java
@@ -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);
     }
diff --git a/src/org/torproject/android/service/StartTorReceiver.java b/src/org/torproject/android/service/StartTorReceiver.java
index 89df596..c89d880 100644
--- a/src/org/torproject/android/service/StartTorReceiver.java
+++ b/src/org/torproject/android/service/StartTorReceiver.java
@@ -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);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits