Bug 1339160 - 4. Use GeckoService to extract libs on update; r=esawin
authorJim Chen <nchen@mozilla.com>
Wed, 15 Feb 2017 17:13:05 -0500
changeset 343202 427fd576729151744a2bdd7f433cdf78c0ba3015
parent 343201 8620e18b5878bdf7f9169364503aff9a910afa47
child 343203 b9ee8724079936ea2adab7d017ff7a3aab61c151
push id31372
push usercbook@mozilla.com
push dateThu, 16 Feb 2017 12:16:10 +0000
treeherdermozilla-central@2737f66ad6ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1339160
milestone54.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 1339160 - 4. Use GeckoService to extract libs on update; r=esawin Use the GeckoService load-libs action to load and extract new libraries when we receive the update broadcast. This makes us not block the UI thread to extract libs, and lets Fennec run normally if the user launches Fennec right after updating.
mobile/android/base/java/org/mozilla/gecko/PackageReplacedReceiver.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
mozglue/android/APKOpen.cpp
--- a/mobile/android/base/java/org/mozilla/gecko/PackageReplacedReceiver.java
+++ b/mobile/android/base/java/org/mozilla/gecko/PackageReplacedReceiver.java
@@ -3,36 +3,29 @@
  * 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 android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.util.Log;
 
-import org.mozilla.gecko.mozglue.GeckoLoader;
+import org.mozilla.gecko.GeckoService;
 
 /**
  * This broadcast receiver receives ACTION_MY_PACKAGE_REPLACED broadcasts and
  * starts procedures that should run after the APK has been updated.
  */
 public class PackageReplacedReceiver extends BroadcastReceiver {
     public static final String ACTION_MY_PACKAGE_REPLACED = "android.intent.action.MY_PACKAGE_REPLACED";
 
     @Override
     public void onReceive(Context context, Intent intent) {
         if (intent == null || !ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
             // This is not the broadcast we are looking for.
             return;
         }
 
-        // Extract Gecko libs to allow them to be loaded from cache on startup.
-        extractGeckoLibs(context);
-    }
-
-    private static void extractGeckoLibs(final Context context) {
-        final String resourcePath = context.getPackageResourcePath();
-        GeckoLoader.loadMozGlue(context);
-        GeckoLoader.extractGeckoLibs(context, resourcePath);
+        // Load new Gecko libs to extract them to cache.
+        context.startService(GeckoService.getIntentToLoadLibs(context));
     }
 }
--- 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
@@ -509,25 +509,16 @@ public final class GeckoLoader {
         sMozGlueLoaded = true;
     }
 
     public synchronized static void loadGeckoLibs(final Context context, final String apkName) {
         loadLibsSetupLocked(context);
         loadGeckoLibsNative(apkName);
     }
 
-    public synchronized static void extractGeckoLibs(final Context context, final String apkName) {
-        loadLibsSetupLocked(context);
-        try {
-            extractGeckoLibsNative(apkName);
-        } catch (Exception e) {
-            Log.e(LOGTAG, "Failing library extraction.", e);
-        }
-    }
-
     private static void setupLocaleEnvironment() {
         putenv("LANG=" + Locale.getDefault().toString());
         NumberFormat nf = NumberFormat.getInstance();
         if (nf instanceof DecimalFormat) {
             DecimalFormat df = (DecimalFormat)nf;
             DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
 
             putenv("LOCALE_DECIMAL_POINT=" + dfs.getDecimalSeparator());
@@ -556,10 +547,9 @@ public final class GeckoLoader {
     // These methods are implemented in mozglue/android/nsGeckoUtils.cpp
     private static native void putenv(String map);
 
     // These methods are implemented in mozglue/android/APKOpen.cpp
     public static native void nativeRun(String[] args, int crashFd, int ipcFd);
     private static native void loadGeckoLibsNative(String apkName);
     private static native void loadSQLiteLibsNative(String apkName);
     private static native void loadNSSLibsNative(String apkName);
-    private static native void extractGeckoLibsNative(String apkName);
 }
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -320,41 +320,16 @@ loadNSSLibs(const char *apkName)
     return FAILURE;
   }
 #endif
 
   return setup_nss_functions(nss_handle, nspr_handle, plc_handle);
 }
 
 extern "C" APKOPEN_EXPORT void MOZ_JNICALL
-Java_org_mozilla_gecko_mozglue_GeckoLoader_extractGeckoLibsNative(
-    JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName)
-{
-  MOZ_ALWAYS_TRUE(!jenv->GetJavaVM(&sJavaVM));
-
-  const char* apkName = jenv->GetStringUTFChars(jApkName, nullptr);
-  if (apkName == nullptr) {
-    return;
-  }
-
-  // Extract and cache native lib to allow for efficient startup from cache.
-  void* handle = dlopenAPKLibrary(apkName, "libxul.so");
-  if (handle) {
-    __android_log_print(ANDROID_LOG_INFO, "GeckoLibLoad",
-                        "Extracted and cached libxul.so.");
-    // We have extracted and cached the lib, we can close it now.
-    __wrap_dlclose(handle);
-  } else {
-    JNI_Throw(jenv, "java/lang/Exception", "Error extracting gecko libraries");
-  }
-
-  jenv->ReleaseStringUTFChars(jApkName, apkName);
-}
-
-extern "C" APKOPEN_EXPORT void MOZ_JNICALL
 Java_org_mozilla_gecko_mozglue_GeckoLoader_loadGeckoLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName)
 {
   jenv->GetJavaVM(&sJavaVM);
 
   const char* str;
   // XXX: java doesn't give us true UTF8, we should figure out something
   // better to do here
   str = jenv->GetStringUTFChars(jApkName, nullptr);