Pass bootComplete to dexopt.
bug: 37165062
Test: After OTA, check bootComplete=false on package updates
Change-Id: I6fc00216020bb16d8ed4f6e839b5e1df0e942700
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 46b981e..2736ba6e 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -467,21 +467,12 @@
void notifyDexLoad(String loadingPackageName, in List<String> dexPaths, String loaderIsa);
/**
- * Ask the package manager to perform dex-opt (if needed) on the given
- * package if it already hasn't done so.
- *
- * In most cases, apps are dexopted in advance and this function will
- * be a no-op.
- */
- boolean performDexOptIfNeeded(String packageName);
-
- /**
* Ask the package manager to perform a dex-opt for the given reason. The package
* manager will map the reason to a compiler filter according to the current system
* configuration.
*/
boolean performDexOpt(String packageName, boolean checkProfiles,
- int compileReason, boolean force);
+ int compileReason, boolean force, boolean bootComplete);
/**
* Ask the package manager to perform a dex-opt with the given compiler filter.
@@ -490,7 +481,7 @@
* definite state.
*/
boolean performDexOptMode(String packageName, boolean checkProfiles,
- String targetCompilerFilter, boolean force);
+ String targetCompilerFilter, boolean force, boolean bootComplete);
/**
* Ask the package manager to perform a dex-opt with the given compiler filter on the
diff --git a/services/core/java/com/android/server/pm/BackgroundDexOptService.java b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
index d364d17..adfd7b3 100644
--- a/services/core/java/com/android/server/pm/BackgroundDexOptService.java
+++ b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
@@ -211,7 +211,8 @@
pm.performDexOpt(pkg,
/* checkProfiles */ false,
PackageManagerService.REASON_BOOT,
- /* force */ false);
+ /* force */ false,
+ /* bootComplete */ true);
}
// Ran to completion, so we abandon our timeslice and do not reschedule.
jobFinished(jobParams, /* reschedule */ false);
@@ -288,7 +289,8 @@
? pm.performDexOpt(pkg,
/* checkProfiles */ true,
PackageManagerService.REASON_BACKGROUND_DEXOPT,
- /* force */ false)
+ /* force */ false,
+ /* bootComplete */ true)
: pm.performDexOptSecondary(pkg,
PackageManagerService.REASON_BACKGROUND_DEXOPT,
/* force */ false);
diff --git a/services/core/java/com/android/server/pm/OtaDexoptService.java b/services/core/java/com/android/server/pm/OtaDexoptService.java
index d93d620..317250b 100644
--- a/services/core/java/com/android/server/pm/OtaDexoptService.java
+++ b/services/core/java/com/android/server/pm/OtaDexoptService.java
@@ -315,7 +315,8 @@
null /* ISAs */, false /* checkProfiles */,
getCompilerFilterForReason(compilationReason),
null /* CompilerStats.PackageStats */,
- mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName));
+ mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName),
+ true /* bootComplete */);
return commands;
}
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index 126ad26..49639b0 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -104,7 +104,8 @@
*/
int performDexOpt(PackageParser.Package pkg, String[] sharedLibraries,
String[] instructionSets, boolean checkProfiles, String targetCompilationFilter,
- CompilerStats.PackageStats packageStats, boolean isUsedByOtherApps) {
+ CompilerStats.PackageStats packageStats, boolean isUsedByOtherApps,
+ boolean bootComplete) {
if (!canOptimizePackage(pkg)) {
return DEX_OPT_SKIPPED;
}
@@ -119,7 +120,7 @@
}
try {
return performDexOptLI(pkg, sharedLibraries, instructionSets, checkProfiles,
- targetCompilationFilter, packageStats, isUsedByOtherApps);
+ targetCompilationFilter, packageStats, isUsedByOtherApps, bootComplete);
} finally {
if (useLock) {
mDexoptWakeLock.release();
@@ -136,7 +137,7 @@
private int performDexOptLI(PackageParser.Package pkg, String[] sharedLibraries,
String[] targetInstructionSets, boolean checkForProfileUpdates,
String targetCompilerFilter, CompilerStats.PackageStats packageStats,
- boolean isUsedByOtherApps) {
+ boolean isUsedByOtherApps, boolean bootComplete) {
final String[] instructionSets = targetInstructionSets != null ?
targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo);
final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
@@ -152,7 +153,7 @@
// paths (b/34169257).
String sharedLibrariesPath = getSharedLibrariesPath(sharedLibraries);
// Get the dexopt flags after getRealCompilerFilter to make sure we get the correct flags.
- final int dexoptFlags = getDexFlags(pkg, compilerFilter);
+ final int dexoptFlags = getDexFlags(pkg, compilerFilter, bootComplete);
int result = DEX_OPT_SKIPPED;
// TODO: Iterate based on dependency hierarchy (currently alphabetically by name)
@@ -274,7 +275,9 @@
@GuardedBy("mInstallLock")
private int dexOptSecondaryDexPathLI(ApplicationInfo info, String path, Set<String> isas,
String compilerFilter, boolean isUsedByOtherApps) {
- int dexoptFlags = getDexFlags(info, compilerFilter) | DEXOPT_SECONDARY_DEX;
+ // Secondary dex files are currently not compiled at boot.
+ int dexoptFlags = getDexFlags(info, compilerFilter, /* bootComplete */ true)
+ | DEXOPT_SECONDARY_DEX;
// Check the app storage and add the appropriate flags.
if (info.dataDir.equals(info.deviceProtectedDataDir)) {
dexoptFlags |= DEXOPT_STORAGE_DE;
@@ -374,11 +377,12 @@
* Computes the dex flags that needs to be pass to installd for the given package and compiler
* filter.
*/
- private int getDexFlags(PackageParser.Package pkg, String compilerFilter) {
- return getDexFlags(pkg.applicationInfo, compilerFilter);
+ private int getDexFlags(PackageParser.Package pkg, String compilerFilter,
+ boolean bootComplete) {
+ return getDexFlags(pkg.applicationInfo, compilerFilter, bootComplete);
}
- private int getDexFlags(ApplicationInfo info, String compilerFilter) {
+ private int getDexFlags(ApplicationInfo info, String compilerFilter, boolean bootComplete) {
int flags = info.flags;
boolean debuggable = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
// Profile guide compiled oat files should not be public.
@@ -389,7 +393,7 @@
(isPublic ? DEXOPT_PUBLIC : 0)
| (debuggable ? DEXOPT_DEBUGGABLE : 0)
| profileFlag
- | DEXOPT_BOOTCOMPLETE;
+ | (bootComplete ? DEXOPT_BOOTCOMPLETE : 0);
return adjustDexoptFlags(dexFlags);
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 2391abd..4c732d7 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -2662,7 +2662,7 @@
}
int[] stats = performDexOptUpgrade(coreApps, false,
- getCompilerFilterForReason(REASON_CORE_APP));
+ getCompilerFilterForReason(REASON_CORE_APP), /* bootComplete */ false);
final int elapsedTimeSeconds =
(int) TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start);
@@ -7305,7 +7305,8 @@
final long startTime = System.nanoTime();
final int[] stats = performDexOptUpgrade(pkgs, mIsPreNUpgrade /* showDialog */,
- getCompilerFilterForReason(causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT));
+ getCompilerFilterForReason(causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT),
+ false /* bootComplete */);
final int elapsedTimeSeconds =
(int) TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime);
@@ -7324,7 +7325,7 @@
* and {@code numberOfPackagesFailed}.
*/
private int[] performDexOptUpgrade(List<PackageParser.Package> pkgs, boolean showDialog,
- String compilerFilter) {
+ String compilerFilter, boolean bootComplete) {
int numberOfPackagesVisited = 0;
int numberOfPackagesOptimized = 0;
@@ -7381,7 +7382,8 @@
int dexOptStatus = performDexOptTraced(pkg.packageName,
false /* checkProfiles */,
compilerFilter,
- false /* force */);
+ false /* force */,
+ bootComplete);
switch (dexOptStatus) {
case PackageDexOptimizer.DEX_OPT_PERFORMED:
numberOfPackagesOptimized++;
@@ -7425,36 +7427,30 @@
mDexManager.notifyDexLoad(ai, dexPaths, loaderIsa, userId);
}
- // TODO: this is not used nor needed. Delete it.
- @Override
- public boolean performDexOptIfNeeded(String packageName) {
- int dexOptStatus = performDexOptTraced(packageName,
- false /* checkProfiles */, getFullCompilerFilter(), false /* force */);
- return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
- }
-
@Override
public boolean performDexOpt(String packageName,
- boolean checkProfiles, int compileReason, boolean force) {
+ boolean checkProfiles, int compileReason, boolean force, boolean bootComplete) {
int dexOptStatus = performDexOptTraced(packageName, checkProfiles,
- getCompilerFilterForReason(compileReason), force);
+ getCompilerFilterForReason(compileReason), force, bootComplete);
return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
@Override
public boolean performDexOptMode(String packageName,
- boolean checkProfiles, String targetCompilerFilter, boolean force) {
+ boolean checkProfiles, String targetCompilerFilter, boolean force,
+ boolean bootComplete) {
int dexOptStatus = performDexOptTraced(packageName, checkProfiles,
- targetCompilerFilter, force);
+ targetCompilerFilter, force, bootComplete);
return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
private int performDexOptTraced(String packageName,
- boolean checkProfiles, String targetCompilerFilter, boolean force) {
+ boolean checkProfiles, String targetCompilerFilter, boolean force,
+ boolean bootComplete) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
try {
return performDexOptInternal(packageName, checkProfiles,
- targetCompilerFilter, force);
+ targetCompilerFilter, force, bootComplete);
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
@@ -7463,7 +7459,8 @@
// Run dexopt on a given package. Returns true if dexopt did not fail, i.e.
// if the package can now be considered up to date for the given filter.
private int performDexOptInternal(String packageName,
- boolean checkProfiles, String targetCompilerFilter, boolean force) {
+ boolean checkProfiles, String targetCompilerFilter, boolean force,
+ boolean bootComplete) {
PackageParser.Package p;
synchronized (mPackages) {
p = mPackages.get(packageName);
@@ -7478,7 +7475,7 @@
try {
synchronized (mInstallLock) {
return performDexOptInternalWithDependenciesLI(p, checkProfiles,
- targetCompilerFilter, force);
+ targetCompilerFilter, force, bootComplete);
}
} finally {
Binder.restoreCallingIdentity(callingId);
@@ -7499,7 +7496,7 @@
private int performDexOptInternalWithDependenciesLI(PackageParser.Package p,
boolean checkProfiles, String targetCompilerFilter,
- boolean force) {
+ boolean force, boolean bootComplete) {
// Select the dex optimizer based on the force parameter.
// Note: The force option is rarely used (cmdline input for testing, mostly), so it's OK to
// allocate an object here.
@@ -7519,12 +7516,13 @@
false /* checkProfiles */,
getCompilerFilterForReason(REASON_NON_SYSTEM_LIBRARY),
getOrCreateCompilerPackageStats(depPackage),
- mDexManager.isUsedByOtherApps(p.packageName));
+ mDexManager.isUsedByOtherApps(p.packageName),
+ bootComplete);
}
}
return pdo.performDexOpt(p, p.usesLibraryFiles, instructionSets, checkProfiles,
targetCompilerFilter, getOrCreateCompilerPackageStats(p),
- mDexManager.isUsedByOtherApps(p.packageName));
+ mDexManager.isUsedByOtherApps(p.packageName), bootComplete);
}
// Performs dexopt on the used secondary dex files belonging to the given package.
@@ -7670,7 +7668,8 @@
// Don't use profiles since that may cause compilation to be skipped.
final int res = performDexOptInternalWithDependenciesLI(pkg,
false /* checkProfiles */, getCompilerFilterForReason(REASON_FORCED_DEXOPT),
- true /* force */);
+ true /* force */,
+ true /* bootComplete */);
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
if (res != PackageDexOptimizer.DEX_OPT_PERFORMED) {
@@ -15242,7 +15241,8 @@
null /* instructionSets */, false /* checkProfiles */,
getCompilerFilterForReason(REASON_INSTALL),
getOrCreateCompilerPackageStats(pkg),
- mDexManager.isUsedByOtherApps(pkg.packageName));
+ mDexManager.isUsedByOtherApps(pkg.packageName),
+ true /* bootComplete */);
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
// Notify BackgroundDexOptService that the package has been changed.
diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
index 2f000c2..dd3af66 100644
--- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -399,7 +399,8 @@
? mInterface.performDexOptSecondary(packageName,
targetCompilerFilter, forceCompilation)
: mInterface.performDexOptMode(packageName,
- checkProfiles, targetCompilerFilter, forceCompilation);
+ checkProfiles, targetCompilerFilter, forceCompilation,
+ true /* bootComplete */);
if (!result) {
failedPackages.add(packageName);
}