From cd8fbd25d3b0e510e626a36767ebbea0282ea2ae Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Sat, 22 Jul 2017 12:33:41 -0700 Subject: Update DexLoadReporter to comply with the new reporting API This is a partial cherry pick of commit 3bec94d78b0a66c4fa5cebd851ea33bcc51916b0. It is partial because it only adapts DexLoadReporter to use the new reporter BaseDexClassLoader.Reporter API. Bug: 38138251 Test: make Merged-In: I2486522fb811f9fc58a44b92642f43a41e7d5bac (cherry picked from commit 3bec94d78b0a66c4fa5cebd851ea33bcc51916b0) Change-Id: I4c41dbeb8a9297caac8b0eb936cf74832569f33e --- core/java/android/app/DexLoadReporter.java | 37 ++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/core/java/android/app/DexLoadReporter.java b/core/java/android/app/DexLoadReporter.java index 13f288ab7454..5f61e07ec46e 100644 --- a/core/java/android/app/DexLoadReporter.java +++ b/core/java/android/app/DexLoadReporter.java @@ -28,6 +28,8 @@ import dalvik.system.VMRuntime; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -86,29 +88,46 @@ import java.util.Set; } @Override - public void report(List dexPaths) { - if (dexPaths.isEmpty()) { + public void report(List classLoadersChain, List classPaths) { + if (classLoadersChain.size() != classPaths.size()) { + Slog.wtf(TAG, "Bad call to DexLoadReporter: argument size mismatch"); return; } + if (classPaths.isEmpty()) { + Slog.wtf(TAG, "Bad call to DexLoadReporter: empty dex paths"); + return; + } + + // The first element of classPaths is the list of dex files that should be registered. + // The classpath is represented as a list of dex files separated by File.pathSeparator. + String[] dexPathsForRegistration = classPaths.get(0).split(File.pathSeparator); + if (dexPathsForRegistration.length == 0) { + // No dex files to register. + return; + } + // Notify the package manager about the dex loads unconditionally. // The load might be for either a primary or secondary dex file. - notifyPackageManager(dexPaths); - // Check for secondary dex files and register them for profiling if - // possible. - registerSecondaryDexForProfiling(dexPaths); + notifyPackageManager(classLoadersChain, classPaths); + // Check for secondary dex files and register them for profiling if possible. + // Note that we only register the dex paths belonging to the first class loader. + registerSecondaryDexForProfiling(dexPathsForRegistration); } - private void notifyPackageManager(List dexPaths) { + private void notifyPackageManager(List ignored, + List classPaths) { String packageName = ActivityThread.currentPackageName(); try { + // Notify only the paths of the first class loader for now. ActivityThread.getPackageManager().notifyDexLoad( - packageName, dexPaths, VMRuntime.getRuntime().vmInstructionSet()); + packageName, Arrays.asList(classPaths.get(0).split(File.pathSeparator)), + VMRuntime.getRuntime().vmInstructionSet()); } catch (RemoteException re) { Slog.e(TAG, "Failed to notify PM about dex load for package " + packageName, re); } } - private void registerSecondaryDexForProfiling(List dexPaths) { + private void registerSecondaryDexForProfiling(String[] dexPaths) { if (!SystemProperties.getBoolean("dalvik.vm.dexopt.secondary", false)) { return; } -- cgit v1.2.3-59-g8ed1b