From 41e3646a3a487aaae301e956442a22b67e7cf587 Mon Sep 17 00:00:00 2001 From: Eugen Sawin Date: Thu, 9 Nov 2017 18:22:16 +0100 Subject: [PATCH] Bug 1415929 - [1.0] Move Android app data directory out of setting to an environment variable. r=snorp --- .../java/org/mozilla/gecko/GeckoSession.java | 11 ----------- .../mozilla/gecko/GeckoSessionSettings.java | 7 ------- .../org/mozilla/gecko/mozglue/GeckoLoader.java | 7 +++++++ .../geckoview/GeckoViewRemoteDebugger.jsm | 18 +++++++++++++----- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java index d0288d0c8df1..56188b77a3ab 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java @@ -6,7 +6,6 @@ package org.mozilla.gecko; -import java.io.File; import java.net.URLConnection; import java.util.ArrayList; import java.util.Arrays; @@ -477,16 +476,6 @@ public class GeckoSession implements Parcelable { 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); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java index 8e401e917c99..e7cfa3de672f 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSessionSettings.java @@ -84,12 +84,6 @@ public final class GeckoSessionSettings implements Parcelable { public static final Key USE_REMOTE_DEBUGGER = new Key("useRemoteDebugger"); - public static final Key DEBUGGER_SOCKET_DIR = - new Key("debuggerSocketDir"); - - /* package */ static final Key DATA_DIR = - new Key("dataDir", /* initOnly */ true, /* values */ null); - private final GeckoSession mSession; private final GeckoBundle mBundle; @@ -108,7 +102,6 @@ public final class GeckoSessionSettings implements Parcelable { 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, diff --git 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 index 5d8909766ca9..2b7dd781a5b0 100644 --- 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 @@ -125,6 +125,13 @@ public final class GeckoLoader { } } + 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); diff --git a/mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm b/mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm index 25ead7c4afb4..4fe8948955f2 100644 --- a/mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm +++ b/mobile/android/modules/geckoview/GeckoViewRemoteDebugger.jsm @@ -50,15 +50,23 @@ class GeckoViewRemoteDebugger extends GeckoViewModule { "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); }