OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base.library_loader; | 5 package org.chromium.base.library_loader; |
6 | 6 |
7 import android.annotation.TargetApi; | |
8 import android.content.Context; | 7 import android.content.Context; |
9 import android.content.pm.ApplicationInfo; | |
10 import android.content.pm.PackageInfo; | |
11 import android.os.AsyncTask; | 8 import android.os.AsyncTask; |
12 import android.os.Build; | |
13 import android.os.SystemClock; | 9 import android.os.SystemClock; |
14 | 10 |
15 import org.chromium.base.CommandLine; | 11 import org.chromium.base.CommandLine; |
16 import org.chromium.base.ContextUtils; | 12 import org.chromium.base.ContextUtils; |
17 import org.chromium.base.Log; | 13 import org.chromium.base.Log; |
18 import org.chromium.base.PackageUtils; | |
19 import org.chromium.base.TraceEvent; | 14 import org.chromium.base.TraceEvent; |
20 import org.chromium.base.annotations.CalledByNative; | 15 import org.chromium.base.annotations.CalledByNative; |
21 import org.chromium.base.annotations.JNINamespace; | 16 import org.chromium.base.annotations.JNINamespace; |
22 import org.chromium.base.metrics.RecordHistogram; | 17 import org.chromium.base.metrics.RecordHistogram; |
23 | 18 |
24 import java.util.concurrent.atomic.AtomicBoolean; | 19 import java.util.concurrent.atomic.AtomicBoolean; |
25 | 20 |
26 import javax.annotation.Nullable; | 21 import javax.annotation.Nullable; |
27 | 22 |
28 /** | 23 /** |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (linker.isChromiumLinkerLibrary(library)) { | 261 if (linker.isChromiumLinkerLibrary(library)) { |
267 if (DEBUG) Log.i(TAG, "ignoring self-linker load"); | 262 if (DEBUG) Log.i(TAG, "ignoring self-linker load"); |
268 continue; | 263 continue; |
269 } | 264 } |
270 | 265 |
271 // Determine where the library should be loaded from. | 266 // Determine where the library should be loaded from. |
272 String zipFilePath = null; | 267 String zipFilePath = null; |
273 String libFilePath = System.mapLibraryName(library); | 268 String libFilePath = System.mapLibraryName(library); |
274 if (Linker.isInZipFile()) { | 269 if (Linker.isInZipFile()) { |
275 // Load directly from the APK. | 270 // Load directly from the APK. |
276 zipFilePath = getLibraryApkPath(context); | 271 zipFilePath = context.getApplicationInfo().sourceDir
; |
277 Log.i(TAG, "Loading " + library + " from within " +
zipFilePath); | 272 Log.i(TAG, "Loading " + library + " from within " +
zipFilePath); |
278 } else { | 273 } else { |
279 // The library is in its own file. | 274 // The library is in its own file. |
280 Log.i(TAG, "Loading " + library); | 275 Log.i(TAG, "Loading " + library); |
281 } | 276 } |
282 | 277 |
283 // Load the library using this Linker. May throw Unsatis
fiedLinkError. | 278 // Load the library using this Linker. May throw Unsatis
fiedLinkError. |
284 loadLibrary(linker, zipFilePath, libFilePath); | 279 loadLibrary(linker, zipFilePath, libFilePath); |
285 } | 280 } |
286 | 281 |
(...skipping 30 matching lines...) Expand all Loading... |
317 throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBR
ARY_WRONG_VERSION); | 312 throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBR
ARY_WRONG_VERSION); |
318 } | 313 } |
319 } | 314 } |
320 | 315 |
321 // Returns whether the given split name is that of the ABI split. | 316 // Returns whether the given split name is that of the ABI split. |
322 private static boolean isAbiSplit(String splitName) { | 317 private static boolean isAbiSplit(String splitName) { |
323 // The split name for the ABI split is manually set in the build rules. | 318 // The split name for the ABI split is manually set in the build rules. |
324 return splitName.startsWith("abi_"); | 319 return splitName.startsWith("abi_"); |
325 } | 320 } |
326 | 321 |
327 // Returns the path to the .apk that holds the native libraries. | |
328 // This is either the main .apk, or the abi split apk. | |
329 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
330 private static String getLibraryApkPath(Context context) { | |
331 ApplicationInfo appInfo = context.getApplicationInfo(); | |
332 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
333 return appInfo.sourceDir; | |
334 } | |
335 PackageInfo packageInfo = PackageUtils.getOwnPackageInfo(context); | |
336 if (packageInfo.splitNames != null) { | |
337 for (int i = 0; i < packageInfo.splitNames.length; ++i) { | |
338 if (isAbiSplit(packageInfo.splitNames[i])) { | |
339 return appInfo.splitSourceDirs[i]; | |
340 } | |
341 } | |
342 } | |
343 return appInfo.sourceDir; | |
344 } | |
345 | |
346 // The WebView requires the Command Line to be switched over before | 322 // The WebView requires the Command Line to be switched over before |
347 // initialization is done. This is okay in the WebView's case since the | 323 // initialization is done. This is okay in the WebView's case since the |
348 // JNI is already loaded by this point. | 324 // JNI is already loaded by this point. |
349 public void switchCommandLineForWebView() { | 325 public void switchCommandLineForWebView() { |
350 synchronized (sLock) { | 326 synchronized (sLock) { |
351 ensureCommandLineSwitchedAlreadyLocked(); | 327 ensureCommandLineSwitchedAlreadyLocked(); |
352 } | 328 } |
353 } | 329 } |
354 | 330 |
355 // Switch the CommandLine over from Java to native if it hasn't already been
done. | 331 // Switch the CommandLine over from Java to native if it hasn't already been
done. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 457 |
482 // Finds the ranges corresponding to the native library pages, forks a new | 458 // Finds the ranges corresponding to the native library pages, forks a new |
483 // process to prefetch these pages and waits for it. The new process then | 459 // process to prefetch these pages and waits for it. The new process then |
484 // terminates. This is blocking. | 460 // terminates. This is blocking. |
485 private static native boolean nativeForkAndPrefetchNativeLibrary(); | 461 private static native boolean nativeForkAndPrefetchNativeLibrary(); |
486 | 462 |
487 // Returns the percentage of the native library code page that are currently
reseident in | 463 // Returns the percentage of the native library code page that are currently
reseident in |
488 // memory. | 464 // memory. |
489 private static native int nativePercentageOfResidentNativeLibraryCode(); | 465 private static native int nativePercentageOfResidentNativeLibraryCode(); |
490 } | 466 } |
OLD | NEW |