diff options
author | feng <feng@chromium.org> | 2014-11-26 16:27:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-27 00:29:05 +0000 |
commit | d9201758ca9e6dc47e36026a4029dae5cc69e4c4 (patch) | |
tree | 1d7697a74d1816307da02566397651e80f4f829a /base | |
parent | d212fc87023b5b01417d7bbc7aaee06f6226a964 (diff) | |
download | chromium_src-d9201758ca9e6dc47e36026a4029dae5cc69e4c4.zip chromium_src-d9201758ca9e6dc47e36026a4029dae5cc69e4c4.tar.gz chromium_src-d9201758ca9e6dc47e36026a4029dae5cc69e4c4.tar.bz2 |
[Android] Remove the workaround code of a platform bug.
From our UMA and operation feedbacks, we don't see such issue anymore.
(We notified the manufactor of the issue and likely they addressed it
in OTA). The cleanup restores native library name to libchrome.so
instead of libchrome.<VER>.so.
BUG=311644
Review URL: https://codereview.chromium.org/759833002
Cr-Commit-Position: refs/heads/master@{#305925}
Diffstat (limited to 'base')
4 files changed, 21 insertions, 235 deletions
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java index 28c688d..89cb5bb 100644 --- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java +++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java @@ -67,11 +67,6 @@ public class LibraryLoader { // directly from the APK file but it was compressed or not aligned. private static boolean sLibraryIsMappableInApk = true; - // One-way switch becomes true if the system library loading failed, - // and the right native library was found and loaded by the hack. - // The flag is used to report UMA stats later. - private static boolean sNativeLibraryHackWasUsed = false; - /** * The same as ensureInitialized(null, false), should only be called * by non-browser processes. @@ -87,27 +82,20 @@ public class LibraryLoader { * * @param context The context in which the method is called, the caller * may pass in a null context if it doesn't know in which context it - * is running, or it doesn't need to work around the issue - * http://b/13216167. - * - * When the context is not null and native library was not extracted - * by Android package manager, the LibraryLoader class - * will extract the native libraries from APK. This is a hack used to - * work around some Sony devices with the following platform bug: - * http://b/13216167. + * is running. * - * @param shouldDeleteOldWorkaroundLibraries The flag tells whether the method - * should delete the old workaround and fallback libraries or not. + * @param shouldDeleteFallbackLibraries The flag tells whether the method + * should delete the fallback libraries or not. */ public static void ensureInitialized( - Context context, boolean shouldDeleteOldWorkaroundLibraries) + Context context, boolean shouldDeleteFallbackLibraries) throws ProcessInitException { synchronized (sLock) { if (sInitialized) { // Already initialized, nothing to do. return; } - loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries); + loadAlreadyLocked(context, shouldDeleteFallbackLibraries); initializeAlreadyLocked(); } } @@ -139,15 +127,15 @@ public class LibraryLoader { * See the comment in doInBackground() for more considerations on this. * * @param context The context the code is running, or null if it doesn't have one. - * @param shouldDeleteOldWorkaroundLibraries The flag tells whether the method - * should delete the old workaround and fallback libraries or not. + * @param shouldDeleteFallbackLibraries The flag tells whether the method + * should delete the old fallback libraries or not. * * @throws ProcessInitException if the native library failed to load. */ - public static void loadNow(Context context, boolean shouldDeleteOldWorkaroundLibraries) + public static void loadNow(Context context, boolean shouldDeleteFallbackLibraries) throws ProcessInitException { synchronized (sLock) { - loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries); + loadAlreadyLocked(context, shouldDeleteFallbackLibraries); } } @@ -164,7 +152,7 @@ public class LibraryLoader { // Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code private static void loadAlreadyLocked( - Context context, boolean shouldDeleteOldWorkaroundLibraries) + Context context, boolean shouldDeleteFallbackLibraries) throws ProcessInitException { try { if (!sLoaded) { @@ -261,29 +249,14 @@ public class LibraryLoader { } else { // Load libraries using the system linker. for (String library : NativeLibraries.LIBRARIES) { - try { - System.loadLibrary(library); - } catch (UnsatisfiedLinkError e) { - if (context != null - && LibraryLoaderHelper.tryLoadLibraryUsingWorkaround(context, - library)) { - sNativeLibraryHackWasUsed = true; - } else { - throw e; - } - } + System.loadLibrary(library); } } - if (context != null && shouldDeleteOldWorkaroundLibraries) { - if (!sNativeLibraryHackWasUsed) { - LibraryLoaderHelper.deleteLibrariesAsynchronously( - context, LibraryLoaderHelper.PACKAGE_MANAGER_WORKAROUND_DIR); - } - if (!fallbackWasUsed) { - LibraryLoaderHelper.deleteLibrariesAsynchronously( - context, LibraryLoaderHelper.LOAD_FROM_APK_FALLBACK_DIR); - } + if (!fallbackWasUsed && context != null + && shouldDeleteFallbackLibraries) { + LibraryLoaderHelper.deleteLibrariesAsynchronously( + context, LibraryLoaderHelper.LOAD_FROM_APK_FALLBACK_DIR); } long stopTime = SystemClock.uptimeMillis(); @@ -373,7 +346,6 @@ public class LibraryLoader { // Called after all native initializations are complete. public static void onNativeInitializationComplete(Context context) { recordBrowserProcessHistogram(context); - nativeRecordNativeLibraryHack(sNativeLibraryHackWasUsed); } // Record Chromium linker histogram state for the main browser process. Called from @@ -452,6 +424,4 @@ public class LibraryLoader { // Get the version of the native library. This is needed so that we can check we // have the right version before initializing the (rest of the) JNI. private static native String nativeGetVersionNumber(); - - private static native void nativeRecordNativeLibraryHack(boolean usedHack); } 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 c185fad..7dd1a29 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); diff --git a/base/android/javatests/src/org/chromium/base/LibraryLoaderHelperTest.java b/base/android/javatests/src/org/chromium/base/LibraryLoaderHelperTest.java deleted file mode 100644 index 6abdb89..0000000 --- a/base/android/javatests/src/org/chromium/base/LibraryLoaderHelperTest.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.base; - -import android.content.Context; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.MediumTest; - -import org.chromium.base.library_loader.LibraryLoaderHelper; - -import java.io.File; - -/** - * Test class for the native library hack. - */ -public class LibraryLoaderHelperTest extends InstrumentationTestCase { - private static final String TAG = "LibraryLoaderHelperTest"; - - @Override - public void setUp() throws Exception { - Context context = getInstrumentation().getTargetContext(); - LibraryLoaderHelper.deleteLibrariesSynchronously( - context, LibraryLoaderHelper.PACKAGE_MANAGER_WORKAROUND_DIR); - } - - @MediumTest - public void testLoadNativeLibraries() { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - Context context = getInstrumentation().getTargetContext(); - File libDir = LibraryLoaderHelper.getLibDir(context, - LibraryLoaderHelper.PACKAGE_MANAGER_WORKAROUND_DIR); - assertTrue(libDir.exists()); - assertTrue(libDir.isDirectory()); - assertEquals(libDir.list().length, 0); - - assertTrue(LibraryLoaderHelper.loadNativeLibrariesUsingWorkaroundForTesting( - context)); - - assertTrue(libDir.list().length > 0); - } - }); - } - - @Override - public void tearDown() throws Exception { - Context context = getInstrumentation().getTargetContext(); - LibraryLoaderHelper.deleteLibrariesSynchronously( - context, LibraryLoaderHelper.PACKAGE_MANAGER_WORKAROUND_DIR); - super.tearDown(); - } -} diff --git a/base/android/library_loader/library_loader_hooks.cc b/base/android/library_loader/library_loader_hooks.cc index 809275d..965d030 100644 --- a/base/android/library_loader/library_loader_hooks.cc +++ b/base/android/library_loader/library_loader_hooks.cc @@ -136,9 +136,5 @@ jstring GetVersionNumber(JNIEnv* env, jclass clazz) { return ConvertUTF8ToJavaString(env, g_library_version_number).Release(); } -static void RecordNativeLibraryHack(JNIEnv*, jclass, jboolean usedHack) { - UMA_HISTOGRAM_BOOLEAN("LibraryLoader.NativeLibraryHack", usedHack); -} - } // namespace android } // namespace base |