Index: base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java |
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java |
index c185fadbe5f4b00a558ed863ead1abfc56d09948..14c99d5500e381077114b2a9d68fd0ccd2280abf 100644 |
--- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java |
+++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java |
@@ -19,7 +19,6 @@ import java.io.InputStream; |
import java.io.OutputStream; |
import java.util.Collection; |
import java.util.Collections; |
-import java.util.HashMap; |
import java.util.HashSet; |
import java.util.Map; |
import java.util.Map.Entry; |
@@ -44,94 +43,16 @@ class UnpackingException extends Exception { |
/** |
* The class provides helper functions to extract native libraries from APK, |
* and load libraries from there. |
- * |
- * The class should be package-visible only, but made public for testing |
- * purpose. |
*/ |
-public class LibraryLoaderHelper { |
+class LibraryLoaderHelper { |
private static final String TAG = "LibraryLoaderHelper"; |
- // Workaround and fallback directories. |
- // TODO(petrcermak): Merge the directories once refactored. |
- public static final String PACKAGE_MANAGER_WORKAROUND_DIR = "lib"; |
- public static final String LOAD_FROM_APK_FALLBACK_DIR = "fallback"; |
+ // Fallback directories. |
+ static final String LOAD_FROM_APK_FALLBACK_DIR = "fallback"; |
rmcilroy
2014/11/26 11:55:53
nit - could you make this "fallback-lib" instead
Feng Qian
2014/11/26 22:07:16
If there are clients already use 'fallback', we ne
rmcilroy
2014/11/26 23:05:53
We do have UMA (ChromiumAndroidLinker.LibraryLoadF
|
private static final int BUFFER_SIZE = 16384; |
/** |
- * One-way switch becomes true if native libraries were unpacked |
- * from APK. |
- */ |
- private static boolean sLibrariesWereUnpacked = false; |
- |
- /** |
- * Loads native libraries using workaround only, skip the library in system |
- * lib path. The method exists only for testing purpose. |
- * Caller must ensure thread safety of this method. |
- * @param context |
- */ |
- public static boolean loadNativeLibrariesUsingWorkaroundForTesting(Context context) { |
- // Although tryLoadLibraryUsingWorkaround might be called multiple times, |
- // libraries should only be unpacked once, this is guaranteed by |
- // sLibrariesWereUnpacked. |
- for (String library : NativeLibraries.LIBRARIES) { |
- if (!tryLoadLibraryUsingWorkaround(context, library)) { |
- return false; |
- } |
- } |
- return true; |
- } |
- |
- /** |
- * Try to load a native library using a workaround of |
- * http://b/13216167. |
- * |
- * Workaround for b/13216167 was adapted from code in |
- * https://googleplex-android-review.git.corp.google.com/#/c/433061 |
- * |
- * More details about http://b/13216167: |
- * PackageManager may fail to update shared library. |
- * |
- * Native library directory in an updated package is a symbolic link |
- * to a directory in /data/app-lib/<package name>, for example: |
- * /data/data/com.android.chrome/lib -> /data/app-lib/com.android.chrome[-1]. |
- * When updating the application, the PackageManager create a new directory, |
- * e.g., /data/app-lib/com.android.chrome-2, and remove the old symlink and |
- * recreate one to the new directory. However, on some devices (e.g. Sony Xperia), |
- * the symlink was updated, but fails to extract new native libraries from |
- * the new apk. |
- * |
- * We make the following changes to alleviate the issue: |
- * 1) name the native library with apk version code, e.g., |
- * libchrome.1750.136.so, 1750.136 is Chrome version number; |
- * 2) first try to load the library using System.loadLibrary, |
- * if that failed due to the library file was not found, |
- * search the named library in a /data/data/com.android.chrome/app_lib |
- * directory. Because of change 1), each version has a different native |
- * library name, so avoid mistakenly using the old native library. |
- * |
- * If named library is not in /data/data/com.android.chrome/app_lib directory, |
- * extract native libraries from apk and cache in the directory. |
- * |
- * This function doesn't throw UnsatisfiedLinkError, the caller needs to |
- * check the return value. |
- */ |
- static boolean tryLoadLibraryUsingWorkaround(Context context, String library) { |
- assert context != null; |
- String libName = System.mapLibraryName(library); |
- File libFile = new File(getLibDir(context, PACKAGE_MANAGER_WORKAROUND_DIR), libName); |
- if (!libFile.exists() && !unpackWorkaroundLibrariesOnce(context)) { |
- return false; |
- } |
- try { |
- System.load(libFile.getAbsolutePath()); |
- return true; |
- } catch (UnsatisfiedLinkError e) { |
- return false; |
- } |
- } |
- |
- /** |
* Returns the directory for holding extracted native libraries. |
* It may create the directory if it doesn't exist. |
* |
@@ -139,7 +60,7 @@ public class LibraryLoaderHelper { |
* @param dirName The name of the directory containing the libraries. |
* @return The directory file object. |
*/ |
- public static File getLibDir(Context context, String dirName) { |
+ static File getLibDir(Context context, String dirName) { |
return context.getDir(dirName, Context.MODE_PRIVATE); |
} |
@@ -150,46 +71,9 @@ public class LibraryLoaderHelper { |
} |
/** |
- * Unpack native libraries from the APK file. The method is supposed to |
- * be called only once. It deletes existing files in unpacked directory |
- * before unpacking. |
- * |
- * @param context |
- * @return true when unpacking was successful, false when failed or called |
- * more than once. |
- */ |
- private static boolean unpackWorkaroundLibrariesOnce(Context context) { |
- if (sLibrariesWereUnpacked) { |
- return false; |
- } |
- sLibrariesWereUnpacked = true; |
- |
- deleteLibrariesSynchronously(context, PACKAGE_MANAGER_WORKAROUND_DIR); |
- File libDir = getLibDir(context, PACKAGE_MANAGER_WORKAROUND_DIR); |
- |
- try { |
- Map<String, File> dstFiles = new HashMap<String, File>(); |
- for (String library : NativeLibraries.LIBRARIES) { |
- String libName = System.mapLibraryName(library); |
- String pathInZipFile = getJniNameInApk(libName); |
- dstFiles.put(pathInZipFile, new File(libDir, libName)); |
- } |
- unpackLibraries(context, dstFiles); |
- return true; |
- } catch (UnpackingException e) { |
- Log.e(TAG, "Failed to unpack native libraries", e); |
- deleteLibrariesSynchronously(context, PACKAGE_MANAGER_WORKAROUND_DIR); |
- return false; |
- } |
- } |
- |
- /** |
* Delete libraries and their directory synchronously. |
- * For testing purpose only. |
- * |
- * @param context |
*/ |
- public static void deleteLibrariesSynchronously(Context context, String dirName) { |
+ private static void deleteLibrariesSynchronously(Context context, String dirName) { |
File libDir = getLibDir(context, dirName); |
deleteObsoleteLibraries(libDir, Collections.<File>emptyList()); |
} |
@@ -197,8 +81,6 @@ public class LibraryLoaderHelper { |
/** |
* Delete libraries and their directory asynchronously. |
* The actual deletion is done in a background thread. |
- * |
- * @param context |
*/ |
static void deleteLibrariesAsynchronously( |
final Context context, final String dirName) { |
@@ -220,7 +102,7 @@ public class LibraryLoaderHelper { |
* @param library Library name. |
* @return name of the fallback copy of the library. |
*/ |
- public static String buildFallbackLibrary(Context context, String library) { |
+ static String buildFallbackLibrary(Context context, String library) { |
try { |
String libName = System.mapLibraryName(library); |
File fallbackLibDir = getLibDir(context, LOAD_FROM_APK_FALLBACK_DIR); |