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

Commit 5e038b00 authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Allow users to specify a compiler filter when installing through adb.

This change adds an adb install flag '--dexopt-compiler-filter FILTER'.
If specified, it overrides the default compiler filter for dexopt
during installation.

Also, this change makes the package manager call dexopt even if the
compiler filter is "skip".

Bug: 323082746
Test: atest CtsCompilationTestCases
Test: "adb install" a non-debuggable app: Dexopt is performed with
  the "speed-profile" filter.
Test: "adb install" a debuggable app: Dexopt is skipped.
Test: "adb install" a debuggable app with "--dexopt-compiler-filter
  verify": Dexopt is performed with the "verify" filter.
Test: "adb install" an app with "--dexopt-compiler-filter bogus": Dexopt
  fails. The installation succeeds with a warning about the dexopt
  failure.
Change-Id: I0385f40ebe3cc77cf998c880889576623683388a
parent d30e9888
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -2797,6 +2797,8 @@ public class PackageInstaller {
        public int developmentInstallFlags = 0;
        /** {@hide} */
        public int unarchiveId = -1;
        /** {@hide} */
        public @Nullable String dexoptCompilerFilter = null;

        private final ArrayMap<String, Integer> mPermissionStates;

@@ -2850,6 +2852,7 @@ public class PackageInstaller {
            applicationEnabledSettingPersistent = source.readBoolean();
            developmentInstallFlags = source.readInt();
            unarchiveId = source.readInt();
            dexoptCompilerFilter = source.readString();
        }

        /** {@hide} */
@@ -2885,6 +2888,7 @@ public class PackageInstaller {
            ret.applicationEnabledSettingPersistent = applicationEnabledSettingPersistent;
            ret.developmentInstallFlags = developmentInstallFlags;
            ret.unarchiveId = unarchiveId;
            ret.dexoptCompilerFilter = dexoptCompilerFilter;
            return ret;
        }

@@ -3563,6 +3567,11 @@ public class PackageInstaller {
            this.unarchiveId = unarchiveId;
        }

        /** @hide */
        public void setDexoptCompilerFilter(@Nullable String dexoptCompilerFilter) {
            this.dexoptCompilerFilter = dexoptCompilerFilter;
        }

        /** @hide */
        @NonNull
        public ArrayMap<String, Integer> getPermissionStates() {
@@ -3622,6 +3631,7 @@ public class PackageInstaller {
                    applicationEnabledSettingPersistent);
            pw.printHexPair("developmentInstallFlags", developmentInstallFlags);
            pw.printPair("unarchiveId", unarchiveId);
            pw.printPair("dexoptCompilerFilter", dexoptCompilerFilter);
            pw.println();
        }

@@ -3667,6 +3677,7 @@ public class PackageInstaller {
            dest.writeBoolean(applicationEnabledSettingPersistent);
            dest.writeInt(developmentInstallFlags);
            dest.writeInt(unarchiveId);
            dest.writeString(dexoptCompilerFilter);
        }

        public static final Parcelable.Creator<SessionParams>
+10 −3
Original line number Diff line number Diff line
@@ -728,7 +728,14 @@ public final class DexOptHelper {
        final int compilationReason =
                dexManager.getCompilationReasonForInstallScenario(
                        installRequest.getInstallScenario());
        return new DexoptOptions(packageName, compilationReason, dexoptFlags);
        final AndroidPackage pkg = ps.getPkg();
        var options = new DexoptOptions(packageName, compilationReason, dexoptFlags);
        if (installRequest.getDexoptCompilerFilter() != null) {
            options = options.overrideCompilerFilter(installRequest.getDexoptCompilerFilter());
        } else if (pkg != null && pkg.isDebuggable()) {
            options = options.overrideCompilerFilter(DexoptParams.COMPILER_FILTER_NOOP);
        }
        return options;
    }

    /**
@@ -772,12 +779,12 @@ public final class DexOptHelper {
                && installRequest.getInstallSource().mInitiatingPackageName.equals("android"))
                : true;

        // Don't skip the dexopt call if the compiler filter is "skip". Instead, call dexopt with
        // the "skip" filter so that ART Service gets notified and skips dexopt itself.
        return (!instantApp || Global.getInt(context.getContentResolver(),
                Global.INSTANT_APP_DEXOPT_ENABLED, 0) != 0)
                && pkg != null
                && !pkg.isDebuggable()
                && (!onIncremental)
                && dexoptOptions.isCompilationEnabled()
                && !isApex
                && performDexOptForRollback;
    }
+4 −1
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ final class InstallArgs {
    final int mDataLoaderType;
    final int mPackageSource;
    final boolean mApplicationEnabledSettingPersistent;
    @Nullable
    final String mDexoptCompilerFilter;

    // The list of instruction sets supported by this app. This is currently
    // only used during the rmdex() phase to clean up resources. We can get rid of this
@@ -73,7 +75,7 @@ final class InstallArgs {
            int autoRevokePermissionsMode, String traceMethod, int traceCookie,
            SigningDetails signingDetails, int installReason, int installScenario,
            boolean forceQueryableOverride, int dataLoaderType, int packageSource,
            boolean applicationEnabledSettingPersistent) {
            boolean applicationEnabledSettingPersistent, String dexoptCompilerFilter) {
        mOriginInfo = originInfo;
        mMoveInfo = moveInfo;
        mInstallFlags = installFlags;
@@ -96,5 +98,6 @@ final class InstallArgs {
        mDataLoaderType = dataLoaderType;
        mPackageSource = packageSource;
        mApplicationEnabledSettingPersistent = applicationEnabledSettingPersistent;
        mDexoptCompilerFilter = dexoptCompilerFilter;
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ final class InstallRequest {
                params.mTraceMethod, params.mTraceCookie, params.mSigningDetails,
                params.mInstallReason, params.mInstallScenario, params.mForceQueryableOverride,
                params.mDataLoaderType, params.mPackageSource,
                params.mApplicationEnabledSettingPersistent);
                params.mApplicationEnabledSettingPersistent, params.mDexoptCompilerFilter);
        mPackageLite = params.mPackageLite;
        mPackageMetrics = new PackageMetrics(this);
        mIsInstallInherit = params.mIsInherit;
@@ -709,6 +709,11 @@ final class InstallRequest {
        return mWarnings;
    }

    @Nullable
    public String getDexoptCompilerFilter() {
        return mInstallArgs != null ? mInstallArgs.mDexoptCompilerFilter : null;
    }

    public void setScanFlags(int scanFlags) {
        mScanFlags = scanFlags;
    }
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class InstallingSession {
    @Nullable
    final DomainSet mPreVerifiedDomains;
    final boolean mHasAppMetadataFile;
    @Nullable final String mDexoptCompilerFilter;

    // For move install
    InstallingSession(OriginInfo originInfo, MoveInfo moveInfo, IPackageInstallObserver2 observer,
@@ -136,6 +137,7 @@ class InstallingSession {
        mApplicationEnabledSettingPersistent = false;
        mPreVerifiedDomains = null;
        mHasAppMetadataFile = false;
        mDexoptCompilerFilter = null;
    }

    InstallingSession(int sessionId, File stagedDir, IPackageInstallObserver2 observer,
@@ -172,6 +174,7 @@ class InstallingSession {
        mApplicationEnabledSettingPersistent = sessionParams.applicationEnabledSettingPersistent;
        mPreVerifiedDomains = preVerifiedDomains;
        mHasAppMetadataFile = hasAppMetadatafile;
        mDexoptCompilerFilter = sessionParams.dexoptCompilerFilter;
    }

    @Override
Loading