From b195811fd6b5dc01ab840c7f34d0bef61d9f2fc6 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Tue, 4 Jan 2011 15:10:53 -0500 Subject: [PATCH] Bug 608042 - Add ability to make fat android builds that extract APK to disk r=dougt a=blocking-fennec --HG-- extra : rebase_source : 60be05d268c70c08a5979e6480e40add3dc72b9d --- embedding/android/GeckoAppShell.java | 23 +++++++++++++++++++++-- other-licenses/android/APKOpen.cpp | 6 ++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index 7633bf54417..0ac37ddf4f7 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -79,6 +79,8 @@ class GeckoAppShell static private final int NOTIFY_IME_CANCELCOMPOSITION = 2; static private final int NOTIFY_IME_FOCUSCHANGE = 3; + static private final long kFreeSpaceThreshold = 19660800L; // 150Mb + /* The Android-side API: API methods that Android calls */ // Initialization methods @@ -92,7 +94,7 @@ class GeckoAppShell public static native void onLowMemory(); public static native void callObserver(String observerKey, String topic, String data); public static native void removeObserver(String observerKey); - public static native void loadLibs(String apkName); + public static native void loadLibs(String apkName, boolean shouldExtract); // java-side stuff public static void loadGeckoLibs(String apkName) { @@ -120,6 +122,13 @@ class GeckoAppShell f = Environment.getDownloadCacheDirectory(); GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath()); + File cacheFile = GeckoApp.mAppContext.getCacheDir(); + GeckoAppShell.putenv("CACHE_PATH=" + cacheFile.getPath()); + + // gingerbread introduces File.getUsableSpace(). We should use that. + StatFs cacheStats = new StatFs(cacheFile.getPath()); + long freeSpace = cacheStats.getFreeBlocks() * cacheStats.getBlockSize(); + File downloadDir = null; if (Build.VERSION.SDK_INT >= 8) downloadDir = GeckoApp.mAppContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); @@ -129,7 +138,17 @@ class GeckoAppShell putLocaleEnv(); - loadLibs(apkName); + boolean shouldExtact = freeSpace > kFreeSpaceThreshold; + if (!shouldExtact) { + // remove any previously extracted libs since we're apparently low + Iterator cacheFiles = Arrays.asList(cacheFile.listFiles()).iterator(); + while (cacheFiles.hasNext()) { + File libFile = (File)cacheFiles.next(); + if (libFile.getName().endsWith(".so")) + libFile.delete(); + } + } + loadLibs(apkName, shouldExtact); } private static void putLocaleEnv() { diff --git a/other-licenses/android/APKOpen.cpp b/other-licenses/android/APKOpen.cpp index d8ba9311813..4bcb7040b0a 100644 --- a/other-licenses/android/APKOpen.cpp +++ b/other-licenses/android/APKOpen.cpp @@ -439,7 +439,7 @@ static void * mozload(const char * path, void *zip, if (extractLibs) { char fullpath[256]; - snprintf(fullpath, 256, "/data/data/" ANDROID_PACKAGE_NAME "/%s", path + 4); + snprintf(fullpath, 256, "%s/%s", getenv("CACHE_PATH"), path + 4); __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "resolved %s to %s", path, fullpath); extractFile(fullpath, entry, data); handle = __wrap_dlopen(fullpath, RTLD_LAZY); @@ -640,8 +640,10 @@ loadLibs(const char *apkName) } extern "C" NS_EXPORT void JNICALL -Java_org_mozilla_gecko_GeckoAppShell_loadLibs(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName) +Java_org_mozilla_gecko_GeckoAppShell_loadLibs(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jboolean jShouldExtract) { + if (jShouldExtract) + extractLibs = 1; const char* str; // XXX: java doesn't give us true UTF8, we should figure out something // better to do here