Bug 1533425 - Look for architecture-specific greprefs.js files on Android r=njn
authorJames Willcox <snorp@snorp.net>
Thu, 14 Mar 2019 19:37:03 +0000
changeset 464052 9f7a585bb83aca4e3ac2ae3681451bc7f2a43372
parent 464051 5a892aa56e3748ce956064e55d05a80bead278eb
child 464053 be4af23f4c1af764eb00603e07a01bea22c51266
push id35707
push userrmaries@mozilla.com
push dateFri, 15 Mar 2019 03:42:43 +0000
treeherdermozilla-central@5ce27c44f79e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1533425
milestone67.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 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
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
modules/libpref/Preferences.cpp
--- 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
@@ -111,16 +111,17 @@ public final class GeckoLoader {
 
                 prefsEnv.append(");\n");
             }
 
             putenv(prefsEnv.toString());
         }
     }
 
+    @SuppressWarnings("deprecation") // for Build.CPU_ABI
     public synchronized static void setupGeckoEnvironment(final Context context,
                                                           final String profilePath,
                                                           final Collection<String> env,
                                                           final Map<String, Object> prefs) {
         for (final String e : env) {
             putenv(e);
         }
 
@@ -171,16 +172,17 @@ public final class GeckoLoader {
 
         final Class<?> crashHandler = GeckoAppShell.getCrashHandlerService();
         if (crashHandler != null) {
             putenv("MOZ_ANDROID_CRASH_HANDLER=" +
                     context.getPackageName() + "/" + crashHandler.getName());
         }
 
         putenv("MOZ_ANDROID_DEVICE_SDK_VERSION=" + Build.VERSION.SDK_INT);
+        putenv("MOZ_ANDROID_CPU_ABI=" + Build.CPU_ABI);
 
         setupInitialPrefs(prefs);
 
         // env from extras could have reset out linker flags; set them again.
         loadLibsSetupLocked(context);
     }
 
     private static void loadLibsSetupLocked(Context context) {
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -4413,28 +4413,44 @@ float MOZ_MAYBE_UNUSED GetPref<float>(co
   // - $app/defaults/preferences/*.js
   //
   // When `$app == $gre`, we additionally load, in the omni.jar case:
   // - jar:$gre/omni.jar!/defaults/preferences/*.js
   //
   // 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<nsZipFind> find;
   nsTArray<nsCString> prefEntries;
   const char* entryName;
   uint16_t entryNameLen;
 
   RefPtr<nsZipArchive> 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.
     rv = jarReader->FindInit("defaults/pref/*.js$", &findPtr);
     NS_ENSURE_SUCCESS(rv, Err("jarReader->FindInit() failed"));
 
     find = findPtr;
     while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {