From 98778b5ae207666763531153873e001597ef22d0 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Thu, 14 Mar 2019 19:37:03 +0000 Subject: [PATCH] Bug 1533425 - Look for architecture-specific greprefs.js files on Android r=njn We want to publish a multi-architecture AAR for GeckoView which includes a single omni.ja, but we archicture-specific changes in greprefs.js that prevent this from working. This patch causes us to try to read an architecture-specific greprefs.js first, which will be provided by the packaging process for the fat AAR. Differential Revision: https://phabricator.services.mozilla.com/D22526 --HG-- extra : moz-landing-system : lando --- .../org/mozilla/gecko/mozglue/GeckoLoader.java | 2 ++ modules/libpref/Preferences.cpp | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 2e13abf45292..2fdbb433f123 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 @@ -116,6 +116,7 @@ public final class GeckoLoader { } } + @SuppressWarnings("deprecation") // for Build.CPU_ABI public synchronized static void setupGeckoEnvironment(final Context context, final String profilePath, final Collection env, @@ -176,6 +177,7 @@ public final class GeckoLoader { } putenv("MOZ_ANDROID_DEVICE_SDK_VERSION=" + Build.VERSION.SDK_INT); + putenv("MOZ_ANDROID_CPU_ABI=" + Build.CPU_ABI); setupInitialPrefs(prefs); diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index 61e88fcd84a0..b2d08dee5970 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -4418,7 +4418,7 @@ float MOZ_MAYBE_UNUSED GetPref(const char* aName, float aDefaultValue) { // Thus, in the omni.jar case, we always load app-specific default // preferences from omni.jar, whether or not `$app == $gre`. - nsresult rv; + nsresult rv = NS_ERROR_FAILURE; nsZipFind* findPtr; nsAutoPtr find; nsTArray prefEntries; @@ -4428,8 +4428,24 @@ float MOZ_MAYBE_UNUSED GetPref(const char* aName, float aDefaultValue) { RefPtr jarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE); if (jarReader) { +#ifdef MOZ_WIDGET_ANDROID + // Try to load an architecture-specific greprefs.js first. This will be + // present in FAT AAR builds of GeckoView on Android. + const char* abi = getenv("MOZ_ANDROID_CPU_ABI"); + if (abi) { + nsAutoCString path; + path.AppendPrintf("%s/greprefs.js", abi); + rv = pref_ReadPrefFromJar(jarReader, path.get()); + } + + if (NS_FAILED(rv)) { + // Fallback to toplevel greprefs.js if arch-specific load fails. + rv = pref_ReadPrefFromJar(jarReader, "greprefs.js"); + } +#else // Load jar:$gre/omni.jar!/greprefs.js. rv = pref_ReadPrefFromJar(jarReader, "greprefs.js"); +#endif NS_ENSURE_SUCCESS(rv, Err("pref_ReadPrefFromJar() failed")); // Load jar:$gre/omni.jar!/defaults/pref/*.js.