Adds an "install scenario" field to the appropriate datastructures

This CL adds an "install scenario" field to several data structures used
by the Package Manager.  This value will be used by a following CL to
adjust the invocation of dexopt based on the indicated use case.

Bug: 173137187
Test: build
Merged-In: I1d0df8edf85a598905a5e7509f6c811df5c20e2e
Change-Id: I1d0df8edf85a598905a5e7509f6c811df5c20e2e
This commit is contained in:
Chris Wailes
2020-10-20 00:03:48 -07:00
parent eb87a5267f
commit d42204a865
4 changed files with 82 additions and 4 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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) {

View File

@@ -14853,6 +14853,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 +14882,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 +14910,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 +15548,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 +15565,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 +15583,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 +15597,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 +15689,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;
}