summaryrefslogtreecommitdiff
path: root/core/java/android/app/LoadedApk.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/app/LoadedApk.java')
-rw-r--r--core/java/android/app/LoadedApk.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index 9ea16a719ceb..afe9651d82f5 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -51,6 +51,7 @@ import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayAdjustments;
+import dalvik.system.BaseDexClassLoader;
import dalvik.system.VMRuntime;
import java.io.File;
@@ -600,6 +601,40 @@ public final class LoadedApk {
VMRuntime.registerAppInfo(profileFile.getPath(), mApplicationInfo.dataDir,
codePaths.toArray(new String[codePaths.size()]), foreignDexProfilesFile.getPath());
+
+ // Setup the reporter to notify package manager of any relevant dex loads.
+ // At this point the primary apk is loaded and will not be reported.
+ // Anything loaded from now on will be tracked as a potential secondary
+ // or foreign dex file. The goal is to enable:
+ // 1) monitoring and compilation of secondary dex file
+ // 2) track foreign dex file usage (used to determined the
+ // compilation filter of apks).
+ if (BaseDexClassLoader.getReporter() != DexLoadReporter.INSTANCE) {
+ // Set the dex load reporter if not already set.
+ // Note that during the app's life cycle different LoadedApks may be
+ // created and loaded (e.g. if two different apps share the same runtime).
+ BaseDexClassLoader.setReporter(DexLoadReporter.INSTANCE);
+ }
+ }
+
+ private static class DexLoadReporter implements BaseDexClassLoader.Reporter {
+ private static final DexLoadReporter INSTANCE = new DexLoadReporter();
+
+ private DexLoadReporter() {}
+
+ @Override
+ public void report(List<String> dexPaths) {
+ if (dexPaths.isEmpty()) {
+ return;
+ }
+ String packageName = ActivityThread.currentPackageName();
+ try {
+ ActivityThread.getPackageManager().notifyDexLoad(
+ packageName, dexPaths, VMRuntime.getRuntime().vmInstructionSet());
+ } catch (RemoteException re) {
+ Slog.e(TAG, "Failed to notify PM about dex load for package " + packageName, re);
+ }
+ }
}
/**