dexopt: Drop native libraries from the class loader context.

Native shared libraries are recently introduced through
<uses-native-library> manifest declaration. This value is
intended to limit the native shared library loading path,
not to limit Dex shared library path.

This CL filters these native libraries from the class loader
context encoded into the oat files.

Without this change, the class loader specified in the odex and
runtime class loader has a discrepancy and the runtime failed to
verify the odex file, falling back to a slow execution path.

Test: Followed the steps below:
  * Install the latest GoogleCamera APK.
  * Run following commands:
  $ adb shell am start com.google.android.GoogleCamera && \
    sleep 5 && \
    adb shell am force-stop com.google.android.GoogleCamera
  $ adb shell cmd package compile -m speed-profile \
    -f com.google.android.GoogleCamera
  $ adb logcat -c && \
    adb shell am start com.google.android.GoogleCamera && \
    sleep 2
  & adb shell 'logcat -d | grep "id.GoogleCamer:"'
  * No "ClassLoaderContext shared library size mismatch."
    warning is observed.

Bug: 191182412
Change-Id: I069aff0386ac51c842703f5fcd75075a30f09cf5
This commit is contained in:
Hajime Morrita
2021-06-21 15:29:20 -07:00
parent c4bb8a2620
commit 9ffa963eff
2 changed files with 8 additions and 1 deletions

View File

@@ -177,8 +177,10 @@ public class PackageDexOptimizer {
private int performDexOptLI(AndroidPackage pkg, @NonNull PackageSetting pkgSetting,
String[] targetInstructionSets, CompilerStats.PackageStats packageStats,
PackageDexUsage.PackageUseInfo packageUseInfo, DexoptOptions options) {
// ClassLoader only refers non-native (jar) shared libraries and must ignore
// native (so) shared libraries. See also LoadedApk#createSharedLibraryLoader().
final List<SharedLibraryInfo> sharedLibraries = pkgSetting.getPkgState()
.getUsesLibraryInfos();
.getNonNativeUsesLibraryInfos();
final String[] instructionSets = targetInstructionSets != null ?
targetInstructionSets : getAppDexInstructionSets(
AndroidPackageUtils.getPrimaryCpuAbi(pkg, pkgSetting),

View File

@@ -28,6 +28,7 @@ import com.android.server.pm.PackageSetting;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* For use by {@link PackageSetting} to maintain functionality that used to exist in
@@ -110,6 +111,10 @@ public class PackageStateUnserialized {
this.overrideSeInfo = other.overrideSeInfo;
}
public @NonNull List<SharedLibraryInfo> getNonNativeUsesLibraryInfos() {
return getUsesLibraryInfos().stream()
.filter((l) -> !l.isNative()).collect(Collectors.toList());
}
// Code below generated by codegen v1.0.14.