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

Commit cc65194e authored by Calin Juravle's avatar Calin Juravle
Browse files

[framework] Pass .dm files to dexopt at install time

Test: DexoptOptionsTest
      adb install foo.apk foo.dm
Bug: 30934496

Change-Id: If7e705a0efc0954a385ec3bfe7a93921c0d83351
parent 928835eb
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -583,7 +583,7 @@ public class ZygoteInit {
                    installd.dexopt(classPathElement, Process.SYSTEM_UID, packageName,
                    installd.dexopt(classPathElement, Process.SYSTEM_UID, packageName,
                            instructionSet, dexoptNeeded, outputPath, dexFlags, compilerFilter,
                            instructionSet, dexoptNeeded, outputPath, dexFlags, compilerFilter,
                            uuid, classLoaderContext, seInfo, false /* downgrade */,
                            uuid, classLoaderContext, seInfo, false /* downgrade */,
                            targetSdkVersion, /*profileName*/ null);
                            targetSdkVersion, /*profileName*/ null, /*dexMetadataPath*/ null);
                } catch (RemoteException | ServiceSpecificException e) {
                } catch (RemoteException | ServiceSpecificException e) {
                    // Ignore (but log), we need this on the classpath for fallback mode.
                    // Ignore (but log), we need this on the classpath for fallback mode.
                    Log.w(TAG, "Failed compiling classpath element for system server: "
                    Log.w(TAG, "Failed compiling classpath element for system server: "
+3 −2
Original line number Original line Diff line number Diff line
@@ -290,13 +290,14 @@ public class Installer extends SystemService {
            int dexoptNeeded, @Nullable String outputPath, int dexFlags,
            int dexoptNeeded, @Nullable String outputPath, int dexFlags,
            String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
            String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
            @Nullable String seInfo, boolean downgrade, int targetSdkVersion,
            @Nullable String seInfo, boolean downgrade, int targetSdkVersion,
            @Nullable String profileName) throws InstallerException {
            @Nullable String profileName, @Nullable String dexMetadataPath)
            throws InstallerException {
        assertValidInstructionSet(instructionSet);
        assertValidInstructionSet(instructionSet);
        if (!checkBeforeRemote()) return;
        if (!checkBeforeRemote()) return;
        try {
        try {
            mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
            mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
                    dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade,
                    dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade,
                    targetSdkVersion, profileName);
                    targetSdkVersion, profileName, dexMetadataPath);
        } catch (Exception e) {
        } catch (Exception e) {
            throw InstallerException.from(e);
            throw InstallerException.from(e);
        }
        }
+5 −4
Original line number Original line Diff line number Diff line
@@ -261,12 +261,12 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
                    String instructionSet, int dexoptNeeded, @Nullable String outputPath,
                    String instructionSet, int dexoptNeeded, @Nullable String outputPath,
                    int dexFlags, String compilerFilter, @Nullable String volumeUuid,
                    int dexFlags, String compilerFilter, @Nullable String volumeUuid,
                    @Nullable String sharedLibraries, @Nullable String seInfo, boolean downgrade,
                    @Nullable String sharedLibraries, @Nullable String seInfo, boolean downgrade,
                    int targetSdkVersion, @Nullable String profileName)
                    int targetSdkVersion, @Nullable String profileName,
                    throws InstallerException {
                    @Nullable String dexMetadataPath) throws InstallerException {
                final StringBuilder builder = new StringBuilder();
                final StringBuilder builder = new StringBuilder();


                // The version. Right now it's 5.
                // The version. Right now it's 6.
                builder.append("5 ");
                builder.append("6 ");


                builder.append("dexopt");
                builder.append("dexopt");


@@ -284,6 +284,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
                encodeParameter(builder, downgrade);
                encodeParameter(builder, downgrade);
                encodeParameter(builder, targetSdkVersion);
                encodeParameter(builder, targetSdkVersion);
                encodeParameter(builder, profileName);
                encodeParameter(builder, profileName);
                encodeParameter(builder, dexMetadataPath);


                commands.add(builder.toString());
                commands.add(builder.toString());
            }
            }
+13 −4
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser;
import android.content.pm.dex.ArtManager;
import android.content.pm.dex.ArtManager;
import android.content.pm.dex.DexMetadataHelper;
import android.os.FileUtils;
import android.os.FileUtils;
import android.os.PowerManager;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.SystemClock;
@@ -209,6 +210,13 @@ public class PackageDexOptimizer {


            String profileName = ArtManager.getProfileName(i == 0 ? null : pkg.splitNames[i - 1]);
            String profileName = ArtManager.getProfileName(i == 0 ? null : pkg.splitNames[i - 1]);


            String dexMetadataPath = null;
            if (options.isDexoptInstallWithDexMetadata()) {
                File dexMetadataFile = DexMetadataHelper.findDexMetadataForFile(new File(path));
                dexMetadataPath = dexMetadataFile == null
                        ? null : dexMetadataFile.getAbsolutePath();
            }

            final boolean isUsedByOtherApps = options.isDexoptAsSharedLibrary()
            final boolean isUsedByOtherApps = options.isDexoptAsSharedLibrary()
                    || packageUseInfo.isUsedByOtherApps(path);
                    || packageUseInfo.isUsedByOtherApps(path);
            final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
            final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
@@ -223,7 +231,7 @@ public class PackageDexOptimizer {
            for (String dexCodeIsa : dexCodeInstructionSets) {
            for (String dexCodeIsa : dexCodeInstructionSets) {
                int newResult = dexOptPath(pkg, path, dexCodeIsa, compilerFilter,
                int newResult = dexOptPath(pkg, path, dexCodeIsa, compilerFilter,
                        profileUpdated, classLoaderContexts[i], dexoptFlags, sharedGid,
                        profileUpdated, classLoaderContexts[i], dexoptFlags, sharedGid,
                        packageStats, options.isDowngrade(), profileName);
                        packageStats, options.isDowngrade(), profileName, dexMetadataPath);
                // The end result is:
                // The end result is:
                //  - FAILED if any path failed,
                //  - FAILED if any path failed,
                //  - PERFORMED if at least one path needed compilation,
                //  - PERFORMED if at least one path needed compilation,
@@ -248,7 +256,7 @@ public class PackageDexOptimizer {
    private int dexOptPath(PackageParser.Package pkg, String path, String isa,
    private int dexOptPath(PackageParser.Package pkg, String path, String isa,
            String compilerFilter, boolean profileUpdated, String classLoaderContext,
            String compilerFilter, boolean profileUpdated, String classLoaderContext,
            int dexoptFlags, int uid, CompilerStats.PackageStats packageStats, boolean downgrade,
            int dexoptFlags, int uid, CompilerStats.PackageStats packageStats, boolean downgrade,
            String profileName) {
            String profileName, String dexMetadataPath) {
        int dexoptNeeded = getDexoptNeeded(path, isa, compilerFilter, classLoaderContext,
        int dexoptNeeded = getDexoptNeeded(path, isa, compilerFilter, classLoaderContext,
                profileUpdated, downgrade);
                profileUpdated, downgrade);
        if (Math.abs(dexoptNeeded) == DexFile.NO_DEXOPT_NEEDED) {
        if (Math.abs(dexoptNeeded) == DexFile.NO_DEXOPT_NEEDED) {
@@ -275,7 +283,7 @@ public class PackageDexOptimizer {
            mInstaller.dexopt(path, uid, pkg.packageName, isa, dexoptNeeded, oatDir, dexoptFlags,
            mInstaller.dexopt(path, uid, pkg.packageName, isa, dexoptNeeded, oatDir, dexoptFlags,
                    compilerFilter, pkg.volumeUuid, classLoaderContext, pkg.applicationInfo.seInfo,
                    compilerFilter, pkg.volumeUuid, classLoaderContext, pkg.applicationInfo.seInfo,
                    false /* downgrade*/, pkg.applicationInfo.targetSdkVersion,
                    false /* downgrade*/, pkg.applicationInfo.targetSdkVersion,
                    profileName);
                    profileName, dexMetadataPath);


            if (packageStats != null) {
            if (packageStats != null) {
                long endTime = System.currentTimeMillis();
                long endTime = System.currentTimeMillis();
@@ -396,7 +404,8 @@ public class PackageDexOptimizer {
                mInstaller.dexopt(path, info.uid, info.packageName, isa, /*dexoptNeeded*/ 0,
                mInstaller.dexopt(path, info.uid, info.packageName, isa, /*dexoptNeeded*/ 0,
                        /*oatDir*/ null, dexoptFlags,
                        /*oatDir*/ null, dexoptFlags,
                        compilerFilter, info.volumeUuid, classLoaderContext, info.seInfoUser,
                        compilerFilter, info.volumeUuid, classLoaderContext, info.seInfoUser,
                        options.isDowngrade(), info.targetSdkVersion, /*profileName*/ null);
                        options.isDowngrade(), info.targetSdkVersion, /*profileName*/ null,
                        /*dexMetadataPath*/ null);
            }
            }


            return DEX_OPT_PERFORMED;
            return DEX_OPT_PERFORMED;
+2 −1
Original line number Original line Diff line number Diff line
@@ -17309,7 +17309,8 @@ Slog.e("TODD",
            // Also, don't fail application installs if the dexopt step fails.
            // Also, don't fail application installs if the dexopt step fails.
            DexoptOptions dexoptOptions = new DexoptOptions(pkg.packageName,
            DexoptOptions dexoptOptions = new DexoptOptions(pkg.packageName,
                    REASON_INSTALL,
                    REASON_INSTALL,
                    DexoptOptions.DEXOPT_BOOT_COMPLETE);
                    DexoptOptions.DEXOPT_BOOT_COMPLETE |
                    DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE);
            mPackageDexOptimizer.performDexOpt(pkg, pkg.usesLibraryFiles,
            mPackageDexOptimizer.performDexOpt(pkg, pkg.usesLibraryFiles,
                    null /* instructionSets */,
                    null /* instructionSets */,
                    getOrCreateCompilerPackageStats(pkg),
                    getOrCreateCompilerPackageStats(pkg),
Loading