| 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; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.SharedPreferences; | |
| 10 import android.content.pm.ApplicationInfo; | 9 import android.content.pm.ApplicationInfo; |
| 11 import android.content.pm.PackageInfo; | 10 import android.content.pm.PackageInfo; |
| 12 import android.content.pm.PackageManager.NameNotFoundException; | |
| 13 import android.os.AsyncTask; | 11 import android.os.AsyncTask; |
| 14 import android.os.Build; | 12 import android.os.Build; |
| 15 import android.os.SystemClock; | 13 import android.os.SystemClock; |
| 16 | 14 |
| 17 import org.chromium.base.CommandLine; | 15 import org.chromium.base.CommandLine; |
| 18 import org.chromium.base.Log; | 16 import org.chromium.base.Log; |
| 19 import org.chromium.base.PackageUtils; | 17 import org.chromium.base.PackageUtils; |
| 20 import org.chromium.base.TraceEvent; | 18 import org.chromium.base.TraceEvent; |
| 21 import org.chromium.base.annotations.CalledByNative; | 19 import org.chromium.base.annotations.CalledByNative; |
| 22 import org.chromium.base.annotations.JNINamespace; | 20 import org.chromium.base.annotations.JNINamespace; |
| 23 import org.chromium.base.metrics.RecordHistogram; | 21 import org.chromium.base.metrics.RecordHistogram; |
| 24 import org.chromium.minting.lib.common.WebAPKConstants; | 22 import org.chromium.minting.lib.common.WebAPKUtils; |
| 25 | 23 |
| 26 import java.util.concurrent.atomic.AtomicBoolean; | 24 import java.util.concurrent.atomic.AtomicBoolean; |
| 27 | 25 |
| 28 import javax.annotation.Nullable; | 26 import javax.annotation.Nullable; |
| 29 | 27 |
| 30 /** | 28 /** |
| 31 * This class provides functionality to load and register the native libraries. | 29 * This class provides functionality to load and register the native libraries. |
| 32 * Callers are allowed to separate loading the libraries from initializing them. | 30 * Callers are allowed to separate loading the libraries from initializing them. |
| 33 * This may be an advantage for Android Webview, where the libraries can be load
ed | 31 * This may be an advantage for Android Webview, where the libraries can be load
ed |
| 34 * by the zygote process, but then needs per process initialization after the | 32 * by the zygote process, but then needs per process initialization after the |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // in the final .apk don't need to be explicitly loaded. | 263 // in the final .apk don't need to be explicitly loaded. |
| 266 if (linker.isChromiumLinkerLibrary(library)) { | 264 if (linker.isChromiumLinkerLibrary(library)) { |
| 267 if (DEBUG) Log.i(TAG, "ignoring self-linker load"); | 265 if (DEBUG) Log.i(TAG, "ignoring self-linker load"); |
| 268 continue; | 266 continue; |
| 269 } | 267 } |
| 270 | 268 |
| 271 // Determine where the library should be loaded from. | 269 // Determine where the library should be loaded from. |
| 272 String zipFilePath = null; | 270 String zipFilePath = null; |
| 273 String libFilePath = System.mapLibraryName(library); | 271 String libFilePath = System.mapLibraryName(library); |
| 274 if (Linker.isInZipFile()) { | 272 if (Linker.isInZipFile()) { |
| 275 SharedPreferences prefs = context.getSharedPreferenc
es( | 273 Context contextForApk = (mLibraryProcessType == Libr
aryProcessType.PROCESS_WEBAPK_CHILD) |
| 276 WebAPKConstants.MINT_PREFS, Context.MODE_PRI
VATE); | 274 ? WebAPKUtils.getHostBrowserContext(context)
: context; |
| 277 String packageString = prefs.getString( | |
| 278 WebAPKConstants.HOST_PACKAGE_PREF, | |
| 279 WebAPKConstants.DEFAULT_HOST_PACKAGE_NAME); | |
| 280 Context remoteContext = context; | |
| 281 if (mLibraryProcessType == LibraryProcessType.PROCES
S_WEBAPK_CHILD) { | |
| 282 try { | |
| 283 // Construct the context of the WebAPK host,
which has native | |
| 284 // libraries that the WebAPK. | |
| 285 Log.w(TAG, "package name from context: %s", | |
| 286 context.getPackageName()); | |
| 287 remoteContext = | |
| 288 context.getApplicationContext().crea
tePackageContext( | |
| 289 packageString, | |
| 290 Context.CONTEXT_IGNORE_SECUR
ITY | |
| 291 | Context.CONTEXT_INCLUDE_CO
DE); | |
| 292 } catch (NameNotFoundException e) { | |
| 293 e.printStackTrace(); | |
| 294 } | |
| 295 } | |
| 296 // Load directly from the APK. | 275 // Load directly from the APK. |
| 297 zipFilePath = getLibraryApkPath(remoteContext); | 276 zipFilePath = getLibraryApkPath(contextForApk); |
| 298 Log.i(TAG, "Loading " + library + " from within " +
zipFilePath); | 277 Log.i(TAG, "Loading " + library + " from within " +
zipFilePath); |
| 299 } else { | 278 } else { |
| 300 // The library is in its own file. | 279 // The library is in its own file. |
| 301 Log.i(TAG, "Loading " + library); | 280 Log.i(TAG, "Loading " + library); |
| 302 } | 281 } |
| 303 | 282 |
| 304 // Load the library using this Linker. May throw Unsatis
fiedLinkError. | 283 // Load the library using this Linker. May throw Unsatis
fiedLinkError. |
| 305 loadLibrary(linker, zipFilePath, libFilePath); | 284 loadLibrary(linker, zipFilePath, libFilePath); |
| 306 } | 285 } |
| 307 | 286 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 493 |
| 515 // Finds the ranges corresponding to the native library pages, forks a new | 494 // Finds the ranges corresponding to the native library pages, forks a new |
| 516 // process to prefetch these pages and waits for it. The new process then | 495 // process to prefetch these pages and waits for it. The new process then |
| 517 // terminates. This is blocking. | 496 // terminates. This is blocking. |
| 518 private static native boolean nativeForkAndPrefetchNativeLibrary(); | 497 private static native boolean nativeForkAndPrefetchNativeLibrary(); |
| 519 | 498 |
| 520 // Returns the percentage of the native library code page that are currently
reseident in | 499 // Returns the percentage of the native library code page that are currently
reseident in |
| 521 // memory. | 500 // memory. |
| 522 private static native int nativePercentageOfResidentNativeLibraryCode(); | 501 private static native int nativePercentageOfResidentNativeLibraryCode(); |
| 523 } | 502 } |
| OLD | NEW |