Merge "Adds restore/setup specific dex flag" into rvc-dev am: 299a251140 am: 3f986577bd

Change-Id: Ida6db89a6a9a904b7ee0dd58dca82d57c5f08549
This commit is contained in:
TreeHugger Robot
2020-04-16 00:00:41 +00:00
committed by Automerger Merge Worker
5 changed files with 27 additions and 4 deletions

View File

@@ -71,6 +71,8 @@ public class Installer extends SystemService {
public static final int DEXOPT_GENERATE_COMPACT_DEX = 1 << 11;
/** Indicates that dexopt should generate an app image */
public static final int DEXOPT_GENERATE_APP_IMAGE = 1 << 12;
/** Indicates that dexopt may be run with different performance / priority tuned for restore */
public static final int DEXOPT_FOR_RESTORE = 1 << 13; // TODO(b/135202722): remove
public static final int FLAG_STORAGE_DE = IInstalld.FLAG_STORAGE_DE;
public static final int FLAG_STORAGE_CE = IInstalld.FLAG_STORAGE_CE;

View File

@@ -22,6 +22,7 @@ import static com.android.server.pm.Installer.DEXOPT_BOOTCOMPLETE;
import static com.android.server.pm.Installer.DEXOPT_DEBUGGABLE;
import static com.android.server.pm.Installer.DEXOPT_ENABLE_HIDDEN_API_CHECKS;
import static com.android.server.pm.Installer.DEXOPT_FORCE;
import static com.android.server.pm.Installer.DEXOPT_FOR_RESTORE;
import static com.android.server.pm.Installer.DEXOPT_GENERATE_APP_IMAGE;
import static com.android.server.pm.Installer.DEXOPT_GENERATE_COMPACT_DEX;
import static com.android.server.pm.Installer.DEXOPT_IDLE_BACKGROUND_JOB;
@@ -706,6 +707,7 @@ public class PackageDexOptimizer {
| (options.isDexoptIdleBackgroundJob() ? DEXOPT_IDLE_BACKGROUND_JOB : 0)
| (generateCompactDex ? DEXOPT_GENERATE_COMPACT_DEX : 0)
| (generateAppImage ? DEXOPT_GENERATE_APP_IMAGE : 0)
| (options.isDexoptInstallForRestore() ? DEXOPT_FOR_RESTORE : 0)
| hiddenApiFlag;
return adjustDexoptFlags(dexFlags);
}

View File

@@ -66,6 +66,8 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_VERSION_DOWNGRADE
import static android.content.pm.PackageManager.INSTALL_INTERNAL;
import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
import static android.content.pm.PackageManager.INSTALL_REASON_DEVICE_RESTORE;
import static android.content.pm.PackageManager.INSTALL_REASON_DEVICE_SETUP;
import static android.content.pm.PackageManager.INSTALL_SUCCEEDED;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK;
@@ -16709,10 +16711,15 @@ public class PackageManagerService extends IPackageManager.Stub
// 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,
DexoptOptions.DEXOPT_BOOT_COMPLETE
| DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE);
flags);
ScanResult result = reconciledPkg.scanResult;
// This mirrors logic from commitReconciledScanResultLocked, where the library files

View File

@@ -61,6 +61,10 @@ public final class DexoptOptions {
// should get the dex metdata file if present.
public static final int DEXOPT_INSTALL_WITH_DEX_METADATA_FILE = 1 << 10;
// When set, indicates that dexopt is being invoked from the install flow during device restore
// or device setup and should be scheduled appropriately.
public static final int DEXOPT_FOR_RESTORE = 1 << 11; // TODO(b/135202722): remove
// The name of package to optimize.
private final String mPackageName;
@@ -99,7 +103,8 @@ public final class DexoptOptions {
DEXOPT_DOWNGRADE |
DEXOPT_AS_SHARED_LIBRARY |
DEXOPT_IDLE_BACKGROUND_JOB |
DEXOPT_INSTALL_WITH_DEX_METADATA_FILE;
DEXOPT_INSTALL_WITH_DEX_METADATA_FILE |
DEXOPT_FOR_RESTORE;
if ((flags & (~validityMask)) != 0) {
throw new IllegalArgumentException("Invalid flags : " + Integer.toHexString(flags));
}
@@ -155,6 +160,10 @@ public final class DexoptOptions {
return (mFlags & DEXOPT_INSTALL_WITH_DEX_METADATA_FILE) != 0;
}
public boolean isDexoptInstallForRestore() {
return (mFlags & DEXOPT_FOR_RESTORE) != 0;
}
public String getSplitName() {
return mSplitName;
}

View File

@@ -54,6 +54,7 @@ public class DexoptOptionsTests {
assertFalse(opt.isForce());
assertFalse(opt.isDexoptIdleBackgroundJob());
assertFalse(opt.isDexoptInstallWithDexMetadata());
assertFalse(opt.isDexoptInstallForRestore());
}
@Test
@@ -67,7 +68,8 @@ public class DexoptOptionsTests {
DexoptOptions.DEXOPT_DOWNGRADE |
DexoptOptions.DEXOPT_AS_SHARED_LIBRARY |
DexoptOptions.DEXOPT_IDLE_BACKGROUND_JOB |
DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE;
DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE |
DexoptOptions.DEXOPT_FOR_RESTORE;
DexoptOptions opt = new DexoptOptions(mPackageName, mCompilerFilter, flags);
assertEquals(mPackageName, opt.getPackageName());
@@ -82,6 +84,7 @@ public class DexoptOptionsTests {
assertTrue(opt.isDexoptAsSharedLibrary());
assertTrue(opt.isDexoptIdleBackgroundJob());
assertTrue(opt.isDexoptInstallWithDexMetadata());
assertTrue(opt.isDexoptInstallForRestore());
}
@Test