Compile secondary dex at boot after OTA

Bug: 38413085
Test: build successful
Change-Id: If080281fb3147fea625bcafce91167e8c1439736
This commit is contained in:
Shubham Ajmera
2017-06-09 15:40:58 -07:00
parent 08a18210fb
commit ce54397368
3 changed files with 41 additions and 18 deletions

View File

@@ -345,6 +345,10 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName), mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName),
true /* bootComplete */); true /* bootComplete */);
mPackageManagerService.getDexManager().dexoptSecondaryDex(pkg.packageName,
getCompilerFilterForReason(compilationReason),
false /* force */,
false /* compileOnlySharedDex */);
return commands; return commands;
} }

View File

@@ -9340,12 +9340,24 @@ public class PackageManagerService extends IPackageManager.Stub
// Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will // Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will
// behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a // behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a
// trade-off worth doing to save boot time work. // trade-off worth doing to save boot time work.
int dexOptStatus = performDexOptTraced(pkg.packageName, int primaryDexOptStaus = performDexOptTraced(pkg.packageName,
false /* checkProfiles */, false /* checkProfiles */,
compilerFilter, compilerFilter,
false /* force */, false /* force */,
bootComplete); bootComplete);
switch (dexOptStatus) {
boolean secondaryDexOptStatus = true;
if (pkg.isSystemApp()) {
// Only dexopt shared secondary dex files belonging to system apps to not slow down
// too much boot after an OTA.
secondaryDexOptStatus = mDexManager.dexoptSecondaryDex(pkg.packageName,
compilerFilter,
false /* force */,
true /* compileOnlySharedDex */);
}
if (secondaryDexOptStatus) {
switch (primaryDexOptStaus) {
case PackageDexOptimizer.DEX_OPT_PERFORMED: case PackageDexOptimizer.DEX_OPT_PERFORMED:
numberOfPackagesOptimized++; numberOfPackagesOptimized++;
break; break;
@@ -9356,9 +9368,12 @@ public class PackageManagerService extends IPackageManager.Stub
numberOfPackagesFailed++; numberOfPackagesFailed++;
break; break;
default: default:
Log.e(TAG, "Unexpected dexopt return code " + dexOptStatus); Log.e(TAG, "Unexpected dexopt return code " + primaryDexOptStaus);
break; break;
} }
} else {
numberOfPackagesFailed++;
}
} }
return new int[] { numberOfPackagesOptimized, numberOfPackagesSkipped, return new int[] { numberOfPackagesOptimized, numberOfPackagesSkipped,
@@ -9559,8 +9574,8 @@ public class PackageManagerService extends IPackageManager.Stub
} else if (isInstantApp(packageName, UserHandle.getCallingUserId())) { } else if (isInstantApp(packageName, UserHandle.getCallingUserId())) {
return false; return false;
} }
mDexManager.reconcileSecondaryDexFiles(packageName); return mDexManager.dexoptSecondaryDex(packageName, compilerFilter, force,
return mDexManager.dexoptSecondaryDex(packageName, compilerFilter, force); /* compileOnlySharedDex*/ false);
} }
public boolean performDexOptSecondary(String packageName, int compileReason, public boolean performDexOptSecondary(String packageName, int compileReason,

View File

@@ -307,7 +307,7 @@ public class DexManager {
public boolean dexoptSecondaryDex(String packageName, int compilerReason, boolean force) { public boolean dexoptSecondaryDex(String packageName, int compilerReason, boolean force) {
return dexoptSecondaryDex(packageName, return dexoptSecondaryDex(packageName,
PackageManagerServiceCompilerMapping.getCompilerFilterForReason(compilerReason), PackageManagerServiceCompilerMapping.getCompilerFilterForReason(compilerReason),
force); force, /* compileOnlySharedDex */ false);
} }
/** /**
@@ -315,7 +315,8 @@ public class DexManager {
* @return true if all secondary dex files were processed successfully (compiled or skipped * @return true if all secondary dex files were processed successfully (compiled or skipped
* because they don't need to be compiled).. * because they don't need to be compiled)..
*/ */
public boolean dexoptSecondaryDex(String packageName, String compilerFilter, boolean force) { public boolean dexoptSecondaryDex(String packageName, String compilerFilter, boolean force,
boolean compileOnlySharedDex) {
// Select the dex optimizer based on the force parameter. // Select the dex optimizer based on the force parameter.
// Forced compilation is done through ForcedUpdatePackageDexOptimizer which will adjust // Forced compilation is done through ForcedUpdatePackageDexOptimizer which will adjust
// the necessary dexopt flags to make sure that compilation is not skipped. This avoid // the necessary dexopt flags to make sure that compilation is not skipped. This avoid
@@ -337,6 +338,9 @@ public class DexManager {
for (Map.Entry<String, DexUseInfo> entry : useInfo.getDexUseInfoMap().entrySet()) { for (Map.Entry<String, DexUseInfo> entry : useInfo.getDexUseInfoMap().entrySet()) {
String dexPath = entry.getKey(); String dexPath = entry.getKey();
DexUseInfo dexUseInfo = entry.getValue(); DexUseInfo dexUseInfo = entry.getValue();
if (compileOnlySharedDex && !dexUseInfo.isUsedByOtherApps()) {
continue;
}
PackageInfo pkg = null; PackageInfo pkg = null;
try { try {
pkg = mPackageManager.getPackageInfo(packageName, /*flags*/0, pkg = mPackageManager.getPackageInfo(packageName, /*flags*/0,