Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Unified Diff: base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java

Issue 759833002: [Android] Remove the workaround code of a platform bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address reviewer's comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7dd1a29a0eafe6c4adfc270cb3950843da86f6de 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
@@ -6,7 +6,6 @@
package org.chromium.base.library_loader;
import android.content.Context;
-import android.os.Build;
import android.util.Log;
import java.io.BufferedOutputStream;
@@ -19,7 +18,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 +42,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";
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,57 +59,14 @@ 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);
}
- @SuppressWarnings("deprecation")
- private static String getJniNameInApk(String libName) {
- // TODO(aurimas): Build.CPU_ABI has been deprecated. Replace it when final L SDK is public.
- return "lib/" + Build.CPU_ABI + "/" + libName;
- }
-
- /**
- * 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 +74,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 +95,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);

Powered by Google App Engine
This is Rietveld 408576698