[tbb-commits] [tor-browser/tor-browser-60.3.0esr-8.5-1] Bug 28051 - Launch Orbot if it isn't running in the background

gk at torproject.org gk at torproject.org
Thu Nov 29 09:24:28 UTC 2018


commit 078d1f89036764b9486cd4de841ad2bfcd748ac0
Author: Matthew Finkel <Matthew.Finkel at gmail.com>
Date:   Wed Nov 14 17:38:08 2018 +0000

    Bug 28051 - Launch Orbot if it isn't running in the background
---
 .../base/java/org/mozilla/gecko/BrowserApp.java    | 64 ++++++----------------
 .../java/org/mozilla/gecko/GeckoApplication.java   | 10 ++++
 .../main/java/org/mozilla/gecko/GeckoAppShell.java | 11 ----
 3 files changed, 26 insertions(+), 59 deletions(-)

diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
index 5efd83398775..814b46f24295 100644
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -181,7 +181,8 @@ import org.mozilla.gecko.widget.GeckoActionProvider;
 import org.mozilla.gecko.widget.SplashScreen;
 import org.mozilla.geckoview.GeckoSession;
 
-import info.guardianproject.netcipher.proxy.OrbotHelper;
+import org.torproject.android.OrbotMainActivity;
+import org.torproject.android.service.TorServiceConstants;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -239,6 +240,7 @@ public class BrowserApp extends GeckoApp
     public static final int ACTIVITY_REQUEST_TRIPLE_READERVIEW = 4001;
     public static final int ACTIVITY_RESULT_TRIPLE_READERVIEW_ADD_BOOKMARK = 4002;
     public static final int ACTIVITY_RESULT_TRIPLE_READERVIEW_IGNORE = 4003;
+    public static final int ACTIVITY_RESULT_ORBOT_LAUNCH = 5001;
 
     public static final String ACTION_VIEW_MULTIPLE = AppConstants.ANDROID_PACKAGE_NAME + ".action.VIEW_MULTIPLE";
 
@@ -267,6 +269,8 @@ public class BrowserApp extends GeckoApp
     private HomeScreen mHomeScreen;
     private TabsPanel mTabsPanel;
 
+    private boolean mOrbotNeedsStart = true;
+
     private boolean showSplashScreen = false;
     private SplashScreen splashScreen;
     /**
@@ -1278,45 +1282,11 @@ public class BrowserApp extends GeckoApp
         }
     }
 
-    private BroadcastReceiver torStatusReceiver = new BroadcastReceiver() {
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (TextUtils.equals(intent.getAction(), OrbotHelper.ACTION_STATUS)) {
-                GeckoAppShell.setTorStatus(intent);
-            }
-        }
-    };
-
     public void checkStartOrbot() {
-        if (!OrbotHelper.isOrbotInstalled(this)) {
-            final Intent installOrbotIntent = OrbotHelper.getOrbotInstallIntent(this);
-
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle(R.string.install_orbot);
-            builder.setMessage(R.string.you_must_have_orbot);
-            builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialogInterface, int i) {
-                    startActivity(installOrbotIntent);
-                }
-            });
-            builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialogInterface, int i) {
-                }
-            });
-            builder.show();
-        } else {
-            /* run in thread so Tor status updates will be received while the
-            * Gecko event sync is blocking the main thread */
-            HandlerThread handlerThread = new HandlerThread("torStatusReceiver");
-            handlerThread.start();
-            Looper looper = handlerThread.getLooper();
-            Handler handler = new Handler(looper);
-            registerReceiver(torStatusReceiver, new IntentFilter(OrbotHelper.ACTION_STATUS),
-                null, handler);
-            OrbotHelper.requestStartTor(this);
+        if (mOrbotNeedsStart) {
+            final String orbotStartAction = "android.intent.action.MAIN";
+            final Intent launchOrbot = new Intent(orbotStartAction, null, this, OrbotMainActivity.class);
+            startActivityForResult(launchOrbot, ACTIVITY_RESULT_ORBOT_LAUNCH, null);
         }
     }
 
@@ -1358,15 +1328,6 @@ public class BrowserApp extends GeckoApp
         for (BrowserAppDelegate delegate : delegates) {
             delegate.onPause(this);
         }
-
-        if (torStatusReceiver != null)
-        {
-            try {
-                unregisterReceiver(torStatusReceiver);
-            } catch (IllegalArgumentException e) {
-                Log.w(LOGTAG, "Tor status receiver couldn't be unregistered", e);
-            }
-        }
     }
 
     @Override
@@ -1801,6 +1762,8 @@ public class BrowserApp extends GeckoApp
         NotificationHelper.destroy();
         GeckoNetworkManager.destroy();
 
+        mOrbotNeedsStart = true;
+
         super.onDestroy();
     }
 
@@ -3018,6 +2981,11 @@ public class BrowserApp extends GeckoApp
                 TabQueueHelper.processTabQueuePromptResponse(resultCode, this);
                 break;
 
+            case ACTIVITY_RESULT_ORBOT_LAUNCH:
+                Log.d(LOGTAG, "onActivityResult: ACTIVITY_RESULT_ORBOT_LAUNCH");
+                mOrbotNeedsStart = false;
+                break;
+
             default:
                 for (final BrowserAppDelegate delegate : delegates) {
                     delegate.onActivityResult(this, requestCode, resultCode, data);
diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
index e896134e0af9..b8e4985332a9 100644
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -62,6 +62,9 @@ import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.UUID;
 
+import org.torproject.android.service.util.Prefs;
+import org.torproject.android.settings.Languages;
+
 public class GeckoApplication extends Application
                               implements HapticFeedbackDelegate {
     private static final String LOG_TAG = "GeckoApplication";
@@ -319,6 +322,13 @@ public class GeckoApplication extends Application
                 "Profile:Create",
                 null);
 
+        // Give Orbot the base Context
+        Prefs.setContext(context);
+
+        // Initialize Orbot's Language settings
+        Languages.setup(BrowserApp.class, R.string.menu_settings);
+        Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
+
         super.onCreate();
     }
 
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
index f67603f853e2..34ba3315f295 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1895,15 +1895,4 @@ public class GeckoAppShell
     public static String getDefaultLocale() {
         return Locale.getDefault().toString();
     }
-
-    public static void setTorStatus(Intent intent) {
-        sTorStatus = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
-        if (OrbotHelper.STATUS_ON.equals(sTorStatus)) {
-            sendPendingUrlIntents();
-        }
-    }
-
-    public static String getTorStatus() {
-        return sTorStatus;
-    }
 }





More information about the tbb-commits mailing list