Bug 1267141 - Part2 - Make extractGeckoLibsNative be a generic function not only for extracting libxul. draft
authorJames Cheng <jacheng@mozilla.com>
Wed, 18 Jan 2017 11:22:35 +0800
changeset 481624 080b82e19dcf359fc51aa9733ec474e6845cdfa1
parent 481623 7c37467768ed20b1c22f255a2dd27ece3894b120
child 481625 05fa7220d3ec38f1fedbf786ab2daf9f3d90e732
push id44881
push userbmo:jacheng@mozilla.com
push dateFri, 10 Feb 2017 06:52:44 +0000
bugs1267141
milestone54.0a1
Bug 1267141 - Part2 - Make extractGeckoLibsNative be a generic function not only for extracting libxul. MozReview-Commit-ID: DWMuRPBNRz
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
@@ -28,11 +28,11 @@ public class PackageReplacedReceiver ext
 
         // 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);
+        GeckoLoader.extractGeckoLibs(context, resourcePath, "libxul.so");
     }
 }
--- 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,20 +509,20 @@ 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) {
+    public synchronized static void extractGeckoLibs(final Context context, final String apkName, final String libPath) {
         loadLibsSetupLocked(context);
         try {
-            extractGeckoLibsNative(apkName);
+            extractGeckoLibsNative(apkName, libPath);
         } catch (Exception e) {
             Log.e(LOGTAG, "Failing library extraction.", e);
         }
     }
 
     private static void setupLocaleEnvironment() {
         putenv("LANG=" + Locale.getDefault().toString());
         NumberFormat nf = NumberFormat.getInstance();
@@ -556,10 +556,10 @@ 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);
+    private static native void extractGeckoLibsNative(String apkName, String libPath);
 }
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -321,37 +321,39 @@ loadNSSLibs(const char *apkName)
   }
 #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)
+    JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jstring jLibPath)
 {
   MOZ_ALWAYS_TRUE(!jenv->GetJavaVM(&sJavaVM));
 
   const char* apkName = jenv->GetStringUTFChars(jApkName, nullptr);
-  if (apkName == nullptr) {
+  const char* libPath = jenv->GetStringUTFChars(jLibPath, nullptr);
+  if (apkName == nullptr || libPath == nullptr) {
     return;
   }
 
   // Extract and cache native lib to allow for efficient startup from cache.
-  void* handle = dlopenAPKLibrary(apkName, "libxul.so");
+  void* handle = dlopenAPKLibrary(apkName, libPath);
   if (handle) {
     __android_log_print(ANDROID_LOG_INFO, "GeckoLibLoad",
-                        "Extracted and cached libxul.so.");
+                        "Extracted and cached %s.", libPath);
     // 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");
+    JNI_Throw(jenv, "java/lang/Exception", "Error extracting library");
   }
 
   jenv->ReleaseStringUTFChars(jApkName, apkName);
+  jenv->ReleaseStringUTFChars(jLibPath, libPath);
 }
 
 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;