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

Commit f8d2e606 authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Add the "--ignore-dexopt-profile" option.

If set, all dexopt profiles are ignored by dexopt during the
installation, including the profile in the DM file and the profile
embedded in the APK file. If an invalid profile is provided during
installation, no warning will be reported by `adb install`.

Context: go/platform-support-for-baseline-profiles

Bug: 257532944
Test: atest CtsCompilationTestCases
Change-Id: Ib933f3443346895c771ed16e4acc7591231d6645
parent 5c205325
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -1477,6 +1477,7 @@ public abstract class PackageManager {
            INSTALL_ALLOW_DOWNGRADE,
            INSTALL_STAGED,
            INSTALL_REQUEST_UPDATE_OWNERSHIP,
            INSTALL_IGNORE_DEXOPT_PROFILE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface InstallFlags {}
@@ -1708,6 +1709,18 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_ARCHIVED = 1 << 27;

    /**
     * If set, all dexopt profiles are ignored by dexopt during the installation, including the
     * profile in the DM file and the profile embedded in the APK file. If an invalid profile is
     * provided during installation, no warning will be reported by {@code adb install}.
     *
     * This option does not affect later dexopt operations (e.g., background dexopt and manual `pm
     * compile` invocations).
     *
     * @hide
     */
    public static final int INSTALL_IGNORE_DEXOPT_PROFILE = 1 << 28;

    /**
     * Flag parameter for {@link #installPackage} to force a non-staged update of an APEX. This is
     * a development-only feature and should not be used on end user devices.
+11 −2
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.DataLoaderType;
import android.content.pm.Flags;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfoLite;
import android.content.pm.PackageInstaller;
@@ -161,6 +162,7 @@ import com.android.internal.util.CollectionUtils;
import com.android.server.EventLogTags;
import com.android.server.LocalManagerRegistry;
import com.android.server.SystemConfig;
import com.android.server.art.model.ArtFlags;
import com.android.server.art.model.DexoptParams;
import com.android.server.art.model.DexoptResult;
import com.android.server.pm.Installer.LegacyDexoptDisabledException;
@@ -2562,8 +2564,15 @@ final class InstallPackageHelper {
                            LocalManagerRegistry.getManager(PackageManagerLocal.class);
                    try (PackageManagerLocal.FilteredSnapshot snapshot =
                                    packageManagerLocal.withFilteredSnapshot()) {
                        DexoptParams params =
                                dexoptOptions.convertToDexoptParams(0 /* extraFlags */);
                        boolean ignoreDexoptProfile =
                                (installRequest.getInstallFlags()
                                        & PackageManager.INSTALL_IGNORE_DEXOPT_PROFILE)
                                != 0;
                        /*@DexoptFlags*/ int extraFlags =
                                ignoreDexoptProfile && Flags.useArtServiceV2()
                                ? ArtFlags.FLAG_IGNORE_PROFILE
                                : 0;
                        DexoptParams params = dexoptOptions.convertToDexoptParams(extraFlags);
                        DexoptResult dexOptResult = DexOptHelper.getArtManagerLocal().dexoptPackage(
                                snapshot, packageName, params);
                        installRequest.onDexoptFinished(dexOptResult);
+11 −1
Original line number Diff line number Diff line
@@ -3703,6 +3703,9 @@ class PackageManagerShellCommand extends ShellCommand {
                    sessionParams.installFlags |=
                            PackageManager.INSTALL_BYPASS_LOW_TARGET_SDK_BLOCK;
                    break;
                case "--ignore-dexopt-profile":
                    sessionParams.installFlags |= PackageManager.INSTALL_IGNORE_DEXOPT_PROFILE;
                    break;
                default:
                    throw new IllegalArgumentException("Unknown option " + opt);
            }
@@ -4799,7 +4802,7 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("       [--enable-rollback]");
        pw.println("       [--force-uuid internal|UUID] [--pkg PACKAGE] [-S BYTES]");
        pw.println("       [--apex] [--non-staged] [--force-non-staged]");
        pw.println("       [--staged-ready-timeout TIMEOUT]");
        pw.println("       [--staged-ready-timeout TIMEOUT] [--ignore-dexopt-profile]");
        pw.println("       [PATH [SPLIT...]|-]");
        pw.println("    Install an application.  Must provide the apk data to install, either as");
        pw.println("    file path(s) or '-' to read from stdin.  Options are:");
@@ -4839,6 +4842,13 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("          milliseconds for pre-reboot verification to complete when");
        pw.println("          performing staged install. This flag is used to alter the waiting");
        pw.println("          time. You can skip the waiting time by specifying a TIMEOUT of '0'");
        pw.println("      --ignore-dexopt-profile: If set, all profiles are ignored by dexopt");
        pw.println("          during the installation, including the profile in the DM file and");
        pw.println("          the profile embedded in the APK file. If an invalid profile is");
        pw.println("          provided during installation, no warning will be reported by `adb");
        pw.println("          install`.");
        pw.println("          This option does not affect later dexopt operations (e.g.,");
        pw.println("          background dexopt and manual `pm compile` invocations).");
        pw.println("");
        pw.println("  install-existing [--user USER_ID|all|current]");
        pw.println("       [--instant] [--full] [--wait] [--restrict-permissions] PACKAGE");