[tor-commits] [orbot/master] let the requesting app know that the user has disabled starting via Intent

n8fr8 at torproject.org n8fr8 at torproject.org
Thu Jun 25 14:59:59 UTC 2015


commit 775135d07a9b2d91818d5b45ecac5af2cb07b0e8
Author: Hans-Christoph Steiner <hans at eds.org>
Date:   Wed Jun 10 18:15:29 2015 -0400

    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
---
 .../android/service/StartTorReceiver.java          |   26 +++++++++++++-------
 .../android/service/TorServiceConstants.java       |    8 ++++--
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/org/torproject/android/service/StartTorReceiver.java b/src/org/torproject/android/service/StartTorReceiver.java
index c89d880..087b01f 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 7921ddc..80b37f8 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";
     





More information about the tor-commits mailing list