Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ffa963e authored by Hajime Morrita's avatar Hajime Morrita
Browse files

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
parent c4bb8a26
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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),
+5 −0
Original line number Diff line number Diff line
@@ -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.