Bug 1415929 - [1.0] Move Android app data directory out of setting to an environment variable. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Thu, 09 Nov 2017 18:22:16 +0100
changeset 444306 4f8dcbc80a0c33e129463d4d351ada407165bf2d
parent 444305 5fa0729021dccefb542e8703d45471e1c58e3d81
child 444307 8daf75d35c4843b10c40652abce7fd0ff8514114
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1415929
milestone58.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 1415929 - [1.0] Move Android app data directory out of setting to an environment variable. r=snorp
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
@@ -1,17 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * vim: ts=4 sw=4 expandtab:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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;
 
-import java.io.File;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Arrays;
 
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.mozglue.JNIObject;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
@@ -472,26 +471,16 @@ public class GeckoSession implements Par
         }
 
         if (!GeckoThread.isLaunched()) {
             final boolean multiprocess =
                     mSettings.getBoolean(GeckoSessionSettings.USE_MULTIPROCESS);
             preload(appContext, /* geckoArgs */ null, multiprocess);
         }
 
-        if (mSettings.getString(GeckoSessionSettings.DATA_DIR) == null) {
-            final File dataDir = new File(appContext.getApplicationInfo().dataDir);
-            try {
-                mSettings.setString(GeckoSessionSettings.DATA_DIR,
-                                    dataDir.getCanonicalPath());
-            } catch (final java.io.IOException e) {
-                Log.e(LOGTAG, "Failed to resolve app data directory");
-            }
-        }
-
         final String chromeUri = mSettings.getString(GeckoSessionSettings.CHROME_URI);
         final int screenId = mSettings.getInt(GeckoSessionSettings.SCREEN_ID);
         final boolean isPrivate = mSettings.getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
 
         mWindow = new Window(mNativeQueue);
 
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
             Window.open(mWindow, mEventDispatcher, mSettings.asBundle(),
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java
@@ -79,22 +79,16 @@ public final class GeckoSessionSettings 
     public static final Key<Integer> DISPLAY_MODE =
         new Key<Integer>("displayMode", /* initOnly */ false,
                          Arrays.asList(DISPLAY_MODE_BROWSER, DISPLAY_MODE_MINIMAL_UI,
                                        DISPLAY_MODE_STANDALONE, DISPLAY_MODE_FULLSCREEN));
 
     public static final Key<Boolean> USE_REMOTE_DEBUGGER =
         new Key<Boolean>("useRemoteDebugger");
 
-    public static final Key<String> DEBUGGER_SOCKET_DIR =
-        new Key<String>("debuggerSocketDir");
-
-    /* package */ static final Key<String> DATA_DIR =
-        new Key<String>("dataDir", /* initOnly */ true, /* values */ null);
-
     private final GeckoSession mSession;
     private final GeckoBundle mBundle;
 
     public GeckoSessionSettings() {
         this(null);
     }
 
     /* package */ GeckoSessionSettings(final GeckoSession session) {
@@ -103,17 +97,16 @@ public final class GeckoSessionSettings 
 
         mBundle.putString(CHROME_URI.name, null);
         mBundle.putInt(SCREEN_ID.name, 0);
         mBundle.putBoolean(USE_TRACKING_PROTECTION.name, false);
         mBundle.putBoolean(USE_PRIVATE_MODE.name, false);
         mBundle.putBoolean(USE_MULTIPROCESS.name, true);
         mBundle.putInt(DISPLAY_MODE.name, DISPLAY_MODE_BROWSER);
         mBundle.putBoolean(USE_REMOTE_DEBUGGER.name, false);
-        mBundle.putString(DEBUGGER_SOCKET_DIR.name, null);
     }
 
     /* package */ GeckoSessionSettings(final GeckoSessionSettings settings,
                                        final GeckoSession session) {
         mSession = session;
         mBundle = new GeckoBundle(settings.mBundle);
     }
 
--- 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
@@ -120,16 +120,23 @@ public final class GeckoLoader {
                 env = intent.getStringExtra("env" + c);
                 Log.d(LOGTAG, "env" + c + ": " + env);
             }
             if (envList.size() > 0) {
               sEnvList = envList.toArray(new String[envList.size()]);
             }
         }
 
+        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");
+        }
+
         putenv("MOZ_ANDROID_PACKAGE_NAME=" + context.getPackageName());
 
         setupDownloadEnvironment(context);
 
         // profile home path
         putenv("HOME=" + profilePath);
 
         // setup the tmp path
--- a/mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm
@@ -45,25 +45,33 @@ class GeckoViewRemoteDebugger extends Ge
   register() {
     if (!DebuggerServer.initialized) {
       DebuggerServer.init();
       DebuggerServer.addBrowserActors("navigator:geckoview");
       DebuggerServer.registerModule(
         "resource://gre/modules/dbg-browser-actors.js");
       DebuggerServer.allowChromeProcess = true;
     }
-    this._isEnabled = true;
-    this._usbDebugger.stop();
 
     let windowId = this.window.QueryInterface(Ci.nsIInterfaceRequestor)
                               .getInterface(Ci.nsIDOMWindowUtils)
                               .outerWindowID;
-    let portOrPath = (this.settings.debuggerSocketDir || this.settings.dataDir) +
-                     "/firefox-debugger-socket-" +
-                     windowId;
+    let env = Cc["@mozilla.org/process/environment;1"]
+              .getService(Ci.nsIEnvironment);
+    let dataDir = env.get("MOZ_ANDROID_DATA_DIR");
+
+    if (!dataDir) {
+      debug("Missing env MOZ_ANDROID_DATA_DIR - aborting debugger server start");
+      return;
+    }
+
+    this._isEnabled = true;
+    this._usbDebugger.stop();
+
+    let portOrPath = dataDir + "/firefox-debugger-socket-" + windowId;
     this._usbDebugger.start(portOrPath);
   }
 
   unregister() {
     this._isEnabled = false;
     this._usbDebugger.stop();
   }
 }