Bug 1433968 - Change how environment variables are passed to GeckoLoader r=jchen
☠☠ backed out by 3e7ffd532e0a ☠ ☠
authorJames Willcox <snorp@snorp.net>
Thu, 19 Apr 2018 15:45:49 -0500
changeset 417744 5ed1e3af37bac190cc189ae3c1aedb40f152410a
parent 417720 635bea9e749d77888d28f422c7ef4b1862e078c4
child 417745 62f865eed952837e551e28ad76f9472525ad0a06
push id33979
push userdluca@mozilla.com
push dateThu, 10 May 2018 21:59:38 +0000
treeherdermozilla-central@aabfe960ab59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1433968
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1433968 - Change how environment variables are passed to GeckoLoader r=jchen Right now we pass a bundle to GeckoLoader.setupGeckoEnvironment() with magic keys representing the environment variables. Instead of this, simply pass a list of Strings. MozReview-Commit-ID: D6mSTnYpnGu
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko;
 
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.process.GeckoProcessManager;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.util.ThreadUtils;
+import org.mozilla.geckoview.BuildConfig;
 
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
@@ -26,16 +27,17 @@ import android.support.annotation.Nullab
 import android.text.TextUtils;
 import android.util.Log;
 
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Locale;
 import java.util.StringTokenizer;
 
 public class GeckoThread extends Thread {
     private static final String LOGTAG = "GeckoThread";
 
     public enum State implements NativeQueue.State {
         // After being loaded by class loader.
@@ -376,16 +378,36 @@ public class GeckoThread extends Thread 
         synchronized (INSTANCE) {
             if (!INSTANCE.mInitialized) {
                 return null;
             }
             return INSTANCE.mExtras;
         }
     }
 
+    private static ArrayList<String> getEnvFromExtras(final Bundle extras) {
+        if (extras == null) {
+            return new ArrayList<>();
+        }
+
+        ArrayList<String> result = new ArrayList<>();
+        if (extras != null) {
+            String env = extras.getString("env0");
+            for (int c = 1; env != null; c++) {
+                if (BuildConfig.DEBUG) {
+                    Log.d(LOGTAG, "env var: " + env);
+                }
+                result.add(env);
+                env = extras.getString("env" + c);
+            }
+        }
+
+        return result;
+    }
+
     @Override
     public void run() {
         Log.i(LOGTAG, "preparing to run Gecko");
 
         Looper.prepare();
         GeckoThread.msgQueue = Looper.myQueue();
         ThreadUtils.sGeckoThread = this;
         ThreadUtils.sGeckoHandler = new Handler();
@@ -437,17 +459,18 @@ public class GeckoThread extends Thread 
 
         final Context context = GeckoAppShell.getApplicationContext();
         final String[] args = isChildProcess() ? mArgs : getMainProcessArgs();
 
         if ((mFlags & FLAG_DEBUGGING) != 0) {
             Log.i(LOGTAG, "RunGecko - args = " + TextUtils.join(" ", args));
         }
 
-        GeckoLoader.setupGeckoEnvironment(context, context.getFilesDir().getPath(), mExtras);
+        final ArrayList<String> env = getEnvFromExtras(mExtras);
+        GeckoLoader.setupGeckoEnvironment(context, context.getFilesDir().getPath(), env);
 
         // And go.
         GeckoLoader.nativeRun(args,
                               mExtras.getInt(EXTRA_PREFS_FD, -1),
                               mExtras.getInt(EXTRA_IPC_FD, -1),
                               mExtras.getInt(EXTRA_CRASH_FD, -1),
                               mExtras.getInt(EXTRA_CRASH_ANNOTATION_FD, -1));
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.mozglue;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.util.Collection;
 import java.util.Locale;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import android.content.Context;
 import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
@@ -87,27 +88,19 @@ public final class GeckoLoader {
         if (oldDir.exists()) {
             delTree(oldDir);
         }
         return tmpDir;
     }
 
     public synchronized static void setupGeckoEnvironment(final Context context,
                                                           final String profilePath,
-                                                          final Bundle extras) {
-        // if we have an intent (we're being launched by an activity)
-        // read in any environmental variables from it here
-        if (extras != null) {
-            String env = extras.getString("env0");
-            Log.d(LOGTAG, "Gecko environment env0: " + env);
-            for (int c = 1; env != null; c++) {
-                putenv(env);
-                env = extras.getString("env" + c);
-                Log.d(LOGTAG, "env" + c + ": " + env);
-            }
+                                                          final Collection<String> env) {
+        for (final String e : env) {
+            putenv(e);
         }
 
         try {
             final File dataDir = new File(context.getApplicationInfo().dataDir);
             putenv("MOZ_ANDROID_DATA_DIR=" + dataDir.getCanonicalPath());
         } catch (final java.io.IOException e) {
             Log.e(LOGTAG, "Failed to resolve app data directory");
         }