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

Commit 21b065b6 authored by Christian Wailes's avatar Christian Wailes Committed by Gerrit Code Review
Browse files

Merge changes from topic "install-hints"

* changes:
  Modify dexopt invocation based on install scenario
  Adds an "install scenario" field to the appropriate datastructures
parents 3a786128 0ef67ee5
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager.DeleteFlags;
import android.content.pm.PackageManager.InstallReason;
import android.content.pm.PackageManager.InstallScenario;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
@@ -1466,6 +1467,14 @@ public class PackageInstaller {
        public int installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
        /** {@hide} */
        public @InstallReason int installReason = PackageManager.INSTALL_REASON_UNKNOWN;
        /**
         * {@hide}
         *
         * This flag indicates which installation scenario best describes this session.  The system
         * may use this value when making decisions about how to handle the installation, such as
         * prioritizing system health or user experience.
         */
        public @InstallScenario int installScenario = PackageManager.INSTALL_SCENARIO_DEFAULT;
        /** {@hide} */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
        public long sizeBytes = -1;
@@ -1529,6 +1538,7 @@ public class PackageInstaller {
            installFlags = source.readInt();
            installLocation = source.readInt();
            installReason = source.readInt();
            installScenario = source.readInt();
            sizeBytes = source.readLong();
            appPackageName = source.readString();
            appIcon = source.readParcelable(null);
@@ -1560,6 +1570,7 @@ public class PackageInstaller {
            ret.installFlags = installFlags;
            ret.installLocation = installLocation;
            ret.installReason = installReason;
            ret.installScenario = installScenario;
            ret.sizeBytes = sizeBytes;
            ret.appPackageName = appPackageName;
            ret.appIcon = appIcon;  // not a copy.
@@ -1985,6 +1996,8 @@ public class PackageInstaller {
            pw.printPair("mode", mode);
            pw.printHexPair("installFlags", installFlags);
            pw.printPair("installLocation", installLocation);
            pw.printPair("installReason", installReason);
            pw.printPair("installScenario", installScenario);
            pw.printPair("sizeBytes", sizeBytes);
            pw.printPair("appPackageName", appPackageName);
            pw.printPair("appIcon", (appIcon != null));
@@ -2018,6 +2031,7 @@ public class PackageInstaller {
            dest.writeInt(installFlags);
            dest.writeInt(installLocation);
            dest.writeInt(installReason);
            dest.writeInt(installScenario);
            dest.writeLong(sizeBytes);
            dest.writeString(appPackageName);
            dest.writeParcelable(appIcon, flags);
@@ -2127,6 +2141,8 @@ public class PackageInstaller {
        /** {@hide} */
        public @InstallReason int installReason;
        /** {@hide} */
        public @InstallReason int installScenario;
        /** {@hide} */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
        public long sizeBytes;
        /** {@hide} */
@@ -2204,6 +2220,7 @@ public class PackageInstaller {

            mode = source.readInt();
            installReason = source.readInt();
            installScenario = source.readInt();
            sizeBytes = source.readLong();
            appPackageName = source.readString();
            appIcon = source.readParcelable(null);
@@ -2734,6 +2751,7 @@ public class PackageInstaller {

            dest.writeInt(mode);
            dest.writeInt(installReason);
            dest.writeInt(installScenario);
            dest.writeLong(sizeBytes);
            dest.writeString(appPackageName);
            dest.writeParcelable(appIcon, flags);
+54 −0
Original line number Diff line number Diff line
@@ -1037,6 +1037,60 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_REASON_ROLLBACK = 5;

    /** @hide */
    @IntDef(prefix = { "INSTALL_SCENARIO_" }, value = {
            INSTALL_SCENARIO_DEFAULT,
            INSTALL_SCENARIO_FAST,
            INSTALL_SCENARIO_BULK,
            INSTALL_SCENARIO_BULK_SECONDARY,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface InstallScenario {}

    /**
     * A value to indicate the lack of CUJ information, disabling all installation scenario logic.
     *
     * @hide
     */
    public static final int INSTALL_SCENARIO_DEFAULT = 0;

    /**
     * Installation scenario providing the fastest “install button to launch" experience possible.
     *
     * @hide
     */
    public static final int INSTALL_SCENARIO_FAST = 1;

    /**
     * Installation scenario indicating a bulk operation with the desired result of a fully
     * optimized application.  If the system is busy or resources are scarce the system will
     * perform less work to avoid impacting system health.
     *
     * Examples of bulk installation scenarios might include device restore, background updates of
     * multiple applications, or user-triggered updates for all applications.
     *
     * The decision to use BULK or BULK_SECONDARY should be based on the desired user experience.
     * BULK_SECONDARY operations may take less time to complete but, when they do, will produce
     * less optimized applications.  The device state (e.g. memory usage or battery status) should
     * not be considered when making this decision as those factors are taken into account by the
     * Package Manager when acting on the installation scenario.
     *
     * @hide
     */
    public static final int INSTALL_SCENARIO_BULK = 2;

    /**
     * Installation scenario indicating a bulk operation that prioritizes minimal system health
     * impact over application optimization.  The application may undergo additional optimization
     * if the system is idle and system resources are abundant.  The more elements of a bulk
     * operation that are marked BULK_SECONDARY, the faster the entire bulk operation will be.
     *
     * See the comments for INSTALL_SCENARIO_BULK for more information.
     *
     * @hide
     */
    public static final int INSTALL_SCENARIO_BULK_SECONDARY = 3;

    /** @hide */
    @IntDef(prefix = { "UNINSTALL_REASON_" }, value = {
            UNINSTALL_REASON_UNKNOWN,
+1 −0
Original line number Diff line number Diff line
@@ -665,6 +665,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {

            info.mode = params.mode;
            info.installReason = params.installReason;
            info.installScenario = params.installScenario;
            info.sizeBytes = params.sizeBytes;
            info.appPackageName = params.appPackageName;
            if (includeIcon) {
+46 −22
Original line number Diff line number Diff line
@@ -677,10 +677,15 @@ public class PackageManagerService extends IPackageManager.Stub
    public static final int REASON_FIRST_BOOT = 0;
    public static final int REASON_BOOT = 1;
    public static final int REASON_INSTALL = 2;
    public static final int REASON_BACKGROUND_DEXOPT = 3;
    public static final int REASON_AB_OTA = 4;
    public static final int REASON_INACTIVE_PACKAGE_DOWNGRADE = 5;
    public static final int REASON_SHARED = 6;
    public static final int REASON_INSTALL_FAST = 3;
    public static final int REASON_INSTALL_BULK = 4;
    public static final int REASON_INSTALL_BULK_SECONDARY = 5;
    public static final int REASON_INSTALL_BULK_DOWNGRADED = 6;
    public static final int REASON_INSTALL_BULK_SECONDARY_DOWNGRADED = 7;
    public static final int REASON_BACKGROUND_DEXOPT = 8;
    public static final int REASON_AB_OTA = 9;
    public static final int REASON_INACTIVE_PACKAGE_DOWNGRADE = 10;
    public static final int REASON_SHARED = 11;
    public static final int REASON_LAST = REASON_SHARED;
@@ -14853,6 +14858,7 @@ public class PackageManagerService extends IPackageManager.Stub
        final VerificationInfo verificationInfo;
        final PackageParser.SigningDetails signingDetails;
        final int installReason;
        final int mInstallScenario;
        @Nullable
        MultiPackageInstallParams mParentInstallParams;
        final long requiredInstalledVersionCode;
@@ -14881,6 +14887,7 @@ public class PackageManagerService extends IPackageManager.Stub
            this.autoRevokePermissionsMode = autoRevokePermissionsMode;
            this.signingDetails = signingDetails;
            this.installReason = installReason;
            this.mInstallScenario = PackageManager.INSTALL_SCENARIO_DEFAULT;
            this.requiredInstalledVersionCode = requiredInstalledVersionCode;
            this.forceQueryableOverride = false;
            this.mDataLoaderType = dataLoaderType;
@@ -14908,6 +14915,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    activeInstallSession.getInstallSource().installerPackageName,
                    activeInstallSession.getInstallerUid(),
                    sessionParams.installReason);
            mInstallScenario = sessionParams.installScenario;
            observer = activeInstallSession.getObserver();
            installFlags = sessionParams.installFlags;
            installSource = activeInstallSession.getInstallSource();
@@ -15545,6 +15553,7 @@ public class PackageManagerService extends IPackageManager.Stub
        final int traceCookie;
        final PackageParser.SigningDetails signingDetails;
        final int installReason;
        final int mInstallScenario;
        final boolean forceQueryableOverride;
        @Nullable final MultiPackageInstallParams mMultiPackageInstallParams;
        final int mDataLoaderType;
@@ -15561,7 +15570,7 @@ public class PackageManagerService extends IPackageManager.Stub
                List<String> whitelistedRestrictedPermissions,
                int autoRevokePermissionsMode,
                String traceMethod, int traceCookie, SigningDetails signingDetails,
                int installReason, boolean forceQueryableOverride,
                int installReason, int installScenario, boolean forceQueryableOverride,
                MultiPackageInstallParams multiPackageInstallParams, int dataLoaderType) {
            this.origin = origin;
            this.move = move;
@@ -15579,6 +15588,7 @@ public class PackageManagerService extends IPackageManager.Stub
            this.traceCookie = traceCookie;
            this.signingDetails = signingDetails;
            this.installReason = installReason;
            this.mInstallScenario = installScenario;
            this.forceQueryableOverride = forceQueryableOverride;
            this.mMultiPackageInstallParams = multiPackageInstallParams;
            this.mDataLoaderType = dataLoaderType;
@@ -15592,7 +15602,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    params.grantedRuntimePermissions, params.whitelistedRestrictedPermissions,
                    params.autoRevokePermissionsMode,
                    params.traceMethod, params.traceCookie, params.signingDetails,
                    params.installReason, params.forceQueryableOverride,
                    params.installReason, params.mInstallScenario, params.forceQueryableOverride,
                    params.mParentInstallParams, params.mDataLoaderType);
        }
@@ -15684,8 +15694,8 @@ public class PackageManagerService extends IPackageManager.Stub
            super(OriginInfo.fromNothing(), null, null, 0, InstallSource.EMPTY,
                    null, null, instructionSets, null, null, null, MODE_DEFAULT, null, 0,
                    PackageParser.SigningDetails.UNKNOWN,
                    PackageManager.INSTALL_REASON_UNKNOWN, false, null /* parent */,
                    DataLoaderType.NONE);
                    PackageManager.INSTALL_REASON_UNKNOWN, PackageManager.INSTALL_SCENARIO_DEFAULT,
                    false, null /* parent */, DataLoaderType.NONE);
            this.codeFile = (codePath != null) ? new File(codePath) : null;
            this.resourceFile = (resourcePath != null) ? new File(resourcePath) : null;
        }
@@ -16993,6 +17003,26 @@ public class PackageManagerService extends IPackageManager.Stub
                    resolveUserIds(reconciledPkg.installArgs.user.getIdentifier()),
                    /* updateReferenceProfileContent= */ true);
            // Compute the compilation reason from the installation scenario.
            final int compilationReason = mDexManager.getCompilationReasonForInstallScenario(
                    reconciledPkg.installArgs.mInstallScenario);
            // Construct the DexoptOptions early to see if we should skip running dexopt.
            //
            // Do not run PackageDexOptimizer through the local performDexOpt
            // method because `pkg` may not be in `mPackages` yet.
            //
            // Also, don't fail application installs if the dexopt step fails.
            final boolean isBackupOrRestore =
                    reconciledPkg.installArgs.installReason == INSTALL_REASON_DEVICE_RESTORE
                    || reconciledPkg.installArgs.installReason == INSTALL_REASON_DEVICE_SETUP;
            final int dexoptFlags = DexoptOptions.DEXOPT_BOOT_COMPLETE
                    | DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE
                    | (isBackupOrRestore ? DexoptOptions.DEXOPT_FOR_RESTORE : 0);
            DexoptOptions dexoptOptions =
                    new DexoptOptions(packageName, compilationReason, dexoptFlags);
            // Check whether we need to dexopt the app.
            //
            // NOTE: it is IMPORTANT to call dexopt:
@@ -17013,11 +17043,18 @@ public class PackageManagerService extends IPackageManager.Stub
            // continuous progress to the useur instead of mysteriously blocking somewhere in the
            // middle of running an instant app. The default behaviour can be overridden
            // via gservices.
            //
            // Furthermore, dexopt may be skipped, depending on the install scenario and current
            // state of the device.
            //
            // TODO(b/174695087): instantApp and onIncremental should be removed and their install
            //       path moved to SCENARIO_FAST.
            final boolean performDexopt =
                    (!instantApp || Global.getInt(mContext.getContentResolver(),
                    Global.INSTANT_APP_DEXOPT_ENABLED, 0) != 0)
                    && !pkg.isDebuggable()
                    && (!onIncremental);
                    && (!onIncremental)
                    && dexoptOptions.isCompilationEnabled();
            if (performDexopt) {
                // Compile the layout resources.
@@ -17028,19 +17065,6 @@ public class PackageManagerService extends IPackageManager.Stub
                }
                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
                // Do not run PackageDexOptimizer through the local performDexOpt
                // method because `pkg` may not be in `mPackages` yet.
                //
                // Also, don't fail application installs if the dexopt step fails.
                int flags = DexoptOptions.DEXOPT_BOOT_COMPLETE
                        | DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE;
                if (reconciledPkg.installArgs.installReason == INSTALL_REASON_DEVICE_RESTORE
                        || reconciledPkg.installArgs.installReason == INSTALL_REASON_DEVICE_SETUP) {
                    flags |= DexoptOptions.DEXOPT_FOR_RESTORE;
                }
                DexoptOptions dexoptOptions = new DexoptOptions(packageName,
                        REASON_INSTALL,
                        flags);
                ScanResult result = reconciledPkg.scanResult;
                // This mirrors logic from commitReconciledScanResultLocked, where the library files
+19 −4
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.pm;

import android.os.SystemProperties;

import com.android.server.pm.dex.DexoptOptions;

import dalvik.system.DexFile;

/**
@@ -26,10 +28,22 @@ import dalvik.system.DexFile;
public class PackageManagerServiceCompilerMapping {
    // Names for compilation reasons.
    public static final String REASON_STRINGS[] = {
            "first-boot", "boot", "install", "bg-dexopt", "ab-ota", "inactive", "shared"
        "first-boot",
        "boot",
        "install",
        "install-fast",
        "install-bulk",
        "install-bulk-secondary",
        "install-bulk-downgraded",
        "install-bulk-secondary-downgraded",
        "bg-dexopt",
        "ab-ota",
        "inactive",
        // "shared" must be the last entry
        "shared"
    };

    static final int REASON_SHARED_INDEX = 6;
    static final int REASON_SHARED_INDEX = REASON_STRINGS.length - 1;

    // Static block to ensure the strings array is of the right length.
    static {
@@ -53,8 +67,9 @@ public class PackageManagerServiceCompilerMapping {
    // exception in case the reason or value are invalid.
    private static String getAndCheckValidity(int reason) {
        String sysPropValue = SystemProperties.get(getSystemPropertyName(reason));
        if (sysPropValue == null || sysPropValue.isEmpty() ||
                !DexFile.isValidCompilerFilter(sysPropValue)) {
        if (sysPropValue == null || sysPropValue.isEmpty()
                || !(sysPropValue.equals(DexoptOptions.COMPILER_FILTER_NOOP)
                        || DexFile.isValidCompilerFilter(sysPropValue))) {
            throw new IllegalStateException("Value \"" + sysPropValue +"\" not valid "
                    + "(reason " + REASON_STRINGS[reason] + ")");
        } else if (!isFilterAllowedForReason(reason, sysPropValue)) {
Loading