Refactor the arguments passed to dexopt invocations
Wrap the arguments passed to the various performDexopt calls into the
DexoptOptions object.
This will make adding extra arguments (like compile only a split) much
easier and avoid extending quite a few internal methods.
Bug: 38138251
Test: adb shell cmd package compile ....
adb shell cmd package bg-dexopt-job ...
install new apps and check that they compiled
runtest -x
services/tests/servicestests/src/com/android/server/pm/dex/DexoptOptionsTests.java
Change-Id: Ia9930edd2dceb7535d6168eceb8e3199c82b6306
This commit is contained in:
@@ -507,14 +507,6 @@ interface IPackageManager {
|
|||||||
oneway void registerDexModule(in String packageName, in String dexModulePath,
|
oneway void registerDexModule(in String packageName, in String dexModulePath,
|
||||||
in boolean isSharedModule, IDexModuleRegisterCallback callback);
|
in boolean isSharedModule, IDexModuleRegisterCallback callback);
|
||||||
|
|
||||||
/**
|
|
||||||
* 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, boolean bootComplete, boolean downgrade);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the package manager to perform a dex-opt with the given compiler filter.
|
* Ask the package manager to perform a dex-opt with the given compiler filter.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.util.Log;
|
|||||||
import com.android.server.pm.dex.DexManager;
|
import com.android.server.pm.dex.DexManager;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
import com.android.server.PinnerService;
|
import com.android.server.PinnerService;
|
||||||
|
import com.android.server.pm.dex.DexoptOptions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -221,12 +222,10 @@ public class BackgroundDexOptService extends JobService {
|
|||||||
// 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 result = pm.performDexOptWithStatus(pkg,
|
int result = pm.performDexOptWithStatus(new DexoptOptions(
|
||||||
/* checkProfiles */ false,
|
pkg,
|
||||||
PackageManagerService.REASON_BOOT,
|
PackageManagerService.REASON_BOOT,
|
||||||
/* force */ false,
|
DexoptOptions.DEXOPT_BOOT_COMPLETE));
|
||||||
/* bootComplete */ true,
|
|
||||||
/* downgrade */ false);
|
|
||||||
if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
||||||
updatedPackages.add(pkg);
|
updatedPackages.add(pkg);
|
||||||
}
|
}
|
||||||
@@ -338,22 +337,22 @@ public class BackgroundDexOptService extends JobService {
|
|||||||
// Optimize package if needed. Note that there can be no race between
|
// Optimize package if needed. Note that there can be no race between
|
||||||
// concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized.
|
// concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized.
|
||||||
boolean success;
|
boolean success;
|
||||||
|
int dexoptFlags =
|
||||||
|
DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES |
|
||||||
|
DexoptOptions.DEXOPT_BOOT_COMPLETE |
|
||||||
|
(downgrade ? DexoptOptions.DEXOPT_DOWNGRADE : 0);
|
||||||
if (is_for_primary_dex) {
|
if (is_for_primary_dex) {
|
||||||
int result = pm.performDexOptWithStatus(pkg,
|
int result = pm.performDexOptWithStatus(new DexoptOptions(pkg,
|
||||||
/* checkProfiles */ true,
|
PackageManagerService.REASON_BACKGROUND_DEXOPT,
|
||||||
reason,
|
dexoptFlags));
|
||||||
false /* forceCompile*/,
|
|
||||||
true /* bootComplete */,
|
|
||||||
downgrade);
|
|
||||||
success = result != PackageDexOptimizer.DEX_OPT_FAILED;
|
success = result != PackageDexOptimizer.DEX_OPT_FAILED;
|
||||||
if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
||||||
updatedPackages.add(pkg);
|
updatedPackages.add(pkg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
success = pm.performDexOptSecondary(pkg,
|
success = pm.performDexOpt(new DexoptOptions(pkg,
|
||||||
reason,
|
PackageManagerService.REASON_BACKGROUND_DEXOPT,
|
||||||
false /* force */,
|
dexoptFlags | DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX));
|
||||||
downgrade);
|
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
// Dexopt succeeded, remove package from the list of failing ones.
|
// Dexopt succeeded, remove package from the list of failing ones.
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.android.server.pm;
|
|||||||
|
|
||||||
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
|
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
|
||||||
import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
|
import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
|
||||||
import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
|
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -35,6 +34,7 @@ import android.util.Slog;
|
|||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.server.pm.Installer.InstallerException;
|
import com.android.server.pm.Installer.InstallerException;
|
||||||
|
import com.android.server.pm.dex.DexoptOptions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@@ -314,19 +314,19 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
|
|||||||
libraryDependencies = NO_LIBRARIES;
|
libraryDependencies = NO_LIBRARIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
optimizer.performDexOpt(pkg, libraryDependencies,
|
optimizer.performDexOpt(pkg, libraryDependencies,
|
||||||
null /* ISAs */, false /* checkProfiles */,
|
null /* ISAs */,
|
||||||
getCompilerFilterForReason(compilationReason),
|
|
||||||
null /* CompilerStats.PackageStats */,
|
null /* CompilerStats.PackageStats */,
|
||||||
mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName),
|
mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName),
|
||||||
true /* bootComplete */,
|
new DexoptOptions(pkg.packageName, compilationReason,
|
||||||
false /* downgrade */);
|
DexoptOptions.DEXOPT_BOOT_COMPLETE));
|
||||||
|
|
||||||
|
mPackageManagerService.getDexManager().dexoptSecondaryDex(
|
||||||
|
new DexoptOptions(pkg.packageName, compilationReason,
|
||||||
|
DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX |
|
||||||
|
DexoptOptions.DEXOPT_BOOT_COMPLETE));
|
||||||
|
|
||||||
mPackageManagerService.getDexManager().dexoptSecondaryDex(pkg.packageName,
|
|
||||||
getCompilerFilterForReason(compilationReason),
|
|
||||||
false /* force */,
|
|
||||||
false /* compileOnlySharedDex */,
|
|
||||||
false /* downgrade */);
|
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ package com.android.server.pm;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageParser;
|
import android.content.pm.PackageParser;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.FileUtils;
|
import android.os.FileUtils;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@@ -34,6 +32,7 @@ import android.util.SparseArray;
|
|||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.util.IndentingPrintWriter;
|
import com.android.internal.util.IndentingPrintWriter;
|
||||||
import com.android.server.pm.Installer.InstallerException;
|
import com.android.server.pm.Installer.InstallerException;
|
||||||
|
import com.android.server.pm.dex.DexoptOptions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -112,18 +111,16 @@ public class PackageDexOptimizer {
|
|||||||
* synchronized on {@link #mInstallLock}.
|
* synchronized on {@link #mInstallLock}.
|
||||||
*/
|
*/
|
||||||
int performDexOpt(PackageParser.Package pkg, String[] sharedLibraries,
|
int performDexOpt(PackageParser.Package pkg, String[] sharedLibraries,
|
||||||
String[] instructionSets, boolean checkProfiles, String targetCompilationFilter,
|
String[] instructionSets, CompilerStats.PackageStats packageStats,
|
||||||
CompilerStats.PackageStats packageStats, boolean isUsedByOtherApps,
|
boolean isUsedByOtherApps, DexoptOptions options) {
|
||||||
boolean bootComplete, boolean downgrade) {
|
|
||||||
if (!canOptimizePackage(pkg)) {
|
if (!canOptimizePackage(pkg)) {
|
||||||
return DEX_OPT_SKIPPED;
|
return DEX_OPT_SKIPPED;
|
||||||
}
|
}
|
||||||
synchronized (mInstallLock) {
|
synchronized (mInstallLock) {
|
||||||
final long acquireTime = acquireWakeLockLI(pkg.applicationInfo.uid);
|
final long acquireTime = acquireWakeLockLI(pkg.applicationInfo.uid);
|
||||||
try {
|
try {
|
||||||
return performDexOptLI(pkg, sharedLibraries, instructionSets, checkProfiles,
|
return performDexOptLI(pkg, sharedLibraries, instructionSets,
|
||||||
targetCompilationFilter, packageStats, isUsedByOtherApps, bootComplete,
|
packageStats, isUsedByOtherApps, options);
|
||||||
downgrade);
|
|
||||||
} finally {
|
} finally {
|
||||||
releaseWakeLockLI(acquireTime);
|
releaseWakeLockLI(acquireTime);
|
||||||
}
|
}
|
||||||
@@ -136,9 +133,8 @@ public class PackageDexOptimizer {
|
|||||||
*/
|
*/
|
||||||
@GuardedBy("mInstallLock")
|
@GuardedBy("mInstallLock")
|
||||||
private int performDexOptLI(PackageParser.Package pkg, String[] sharedLibraries,
|
private int performDexOptLI(PackageParser.Package pkg, String[] sharedLibraries,
|
||||||
String[] targetInstructionSets, boolean checkForProfileUpdates,
|
String[] targetInstructionSets, CompilerStats.PackageStats packageStats,
|
||||||
String targetCompilerFilter, CompilerStats.PackageStats packageStats,
|
boolean isUsedByOtherApps, DexoptOptions options) {
|
||||||
boolean isUsedByOtherApps, boolean bootComplete, boolean downgrade) {
|
|
||||||
final String[] instructionSets = targetInstructionSets != null ?
|
final String[] instructionSets = targetInstructionSets != null ?
|
||||||
targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo);
|
targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo);
|
||||||
final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
|
final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
|
||||||
@@ -146,13 +142,13 @@ public class PackageDexOptimizer {
|
|||||||
final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
|
final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
|
||||||
|
|
||||||
final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
|
final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
|
||||||
targetCompilerFilter, isUsedByOtherApps);
|
options.getCompilerFilter(), isUsedByOtherApps);
|
||||||
final boolean profileUpdated = checkForProfileUpdates &&
|
final boolean profileUpdated = options.isCheckForProfileUpdates() &&
|
||||||
isProfileUpdated(pkg, sharedGid, compilerFilter);
|
isProfileUpdated(pkg, sharedGid, compilerFilter);
|
||||||
|
|
||||||
final String sharedLibrariesPath = getSharedLibrariesPath(sharedLibraries);
|
final String sharedLibrariesPath = getSharedLibrariesPath(sharedLibraries);
|
||||||
// Get the dexopt flags after getRealCompilerFilter to make sure we get the correct flags.
|
// Get the dexopt flags after getRealCompilerFilter to make sure we get the correct flags.
|
||||||
final int dexoptFlags = getDexFlags(pkg, compilerFilter, bootComplete);
|
final int dexoptFlags = getDexFlags(pkg, compilerFilter, options.isBootComplete());
|
||||||
// Get the dependencies of each split in the package. For each code path in the package,
|
// Get the dependencies of each split in the package. For each code path in the package,
|
||||||
// this array contains the relative paths of each split it depends on, separated by colons.
|
// this array contains the relative paths of each split it depends on, separated by colons.
|
||||||
String[] splitDependencies = getSplitDependencies(pkg);
|
String[] splitDependencies = getSplitDependencies(pkg);
|
||||||
@@ -176,7 +172,7 @@ public class PackageDexOptimizer {
|
|||||||
for (String dexCodeIsa : dexCodeInstructionSets) {
|
for (String dexCodeIsa : dexCodeInstructionSets) {
|
||||||
int newResult = dexOptPath(pkg, path, dexCodeIsa, compilerFilter, profileUpdated,
|
int newResult = dexOptPath(pkg, path, dexCodeIsa, compilerFilter, profileUpdated,
|
||||||
sharedLibrariesPathWithSplits, dexoptFlags, sharedGid, packageStats,
|
sharedLibrariesPathWithSplits, dexoptFlags, sharedGid, packageStats,
|
||||||
downgrade);
|
options.isDowngrade());
|
||||||
// The end result is:
|
// The end result is:
|
||||||
// - FAILED if any path failed,
|
// - FAILED if any path failed,
|
||||||
// - PERFORMED if at least one path needed compilation,
|
// - PERFORMED if at least one path needed compilation,
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ import com.android.server.pm.PermissionsState.PermissionState;
|
|||||||
import com.android.server.pm.Settings.DatabaseVersion;
|
import com.android.server.pm.Settings.DatabaseVersion;
|
||||||
import com.android.server.pm.Settings.VersionInfo;
|
import com.android.server.pm.Settings.VersionInfo;
|
||||||
import com.android.server.pm.dex.DexManager;
|
import com.android.server.pm.dex.DexManager;
|
||||||
|
import com.android.server.pm.dex.DexoptOptions;
|
||||||
import com.android.server.pm.dex.PackageDexUsage;
|
import com.android.server.pm.dex.PackageDexUsage;
|
||||||
import com.android.server.storage.DeviceStorageMonitorInternal;
|
import com.android.server.storage.DeviceStorageMonitorInternal;
|
||||||
|
|
||||||
@@ -9365,21 +9366,22 @@ 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 primaryDexOptStaus = performDexOptTraced(pkg.packageName,
|
int dexoptFlags = bootComplete ? DexoptOptions.DEXOPT_BOOT_COMPLETE : 0;
|
||||||
false /* checkProfiles */,
|
int primaryDexOptStaus = performDexOptTraced(new DexoptOptions(
|
||||||
|
pkg.packageName,
|
||||||
compilerFilter,
|
compilerFilter,
|
||||||
false /* force */,
|
dexoptFlags));
|
||||||
bootComplete,
|
|
||||||
false /* downgrade */);
|
|
||||||
|
|
||||||
if (pkg.isSystemApp()) {
|
if (pkg.isSystemApp()) {
|
||||||
// Only dexopt shared secondary dex files belonging to system apps to not slow down
|
// Only dexopt shared secondary dex files belonging to system apps to not slow down
|
||||||
// too much boot after an OTA.
|
// too much boot after an OTA.
|
||||||
mDexManager.dexoptSecondaryDex(pkg.packageName,
|
int secondaryDexoptFlags = dexoptFlags |
|
||||||
|
DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX |
|
||||||
|
DexoptOptions.DEXOPT_ONLY_SHARED_DEX;
|
||||||
|
mDexManager.dexoptSecondaryDex(new DexoptOptions(
|
||||||
|
pkg.packageName,
|
||||||
compilerFilter,
|
compilerFilter,
|
||||||
false /* force */,
|
secondaryDexoptFlags));
|
||||||
true /* compileOnlySharedDex */,
|
|
||||||
false /* downgrade */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(shubhamajmera): Record secondary dexopt stats.
|
// TODO(shubhamajmera): Record secondary dexopt stats.
|
||||||
@@ -9462,20 +9464,53 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask the package manager to perform a dex-opt with the given compiler filter.
|
||||||
|
*
|
||||||
|
* Note: exposed only for the shell command to allow moving packages explicitly to a
|
||||||
|
* definite state.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean performDexOpt(String packageName,
|
public boolean performDexOptMode(String packageName,
|
||||||
boolean checkProfiles, int compileReason, boolean force, boolean bootComplete,
|
boolean checkProfiles, String targetCompilerFilter, boolean force,
|
||||||
boolean downgrade) {
|
boolean bootComplete) {
|
||||||
|
int flags = (checkProfiles ? DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES : 0) |
|
||||||
|
(force ? DexoptOptions.DEXOPT_FORCE : 0) |
|
||||||
|
(bootComplete ? DexoptOptions.DEXOPT_BOOT_COMPLETE : 0);
|
||||||
|
return performDexOpt(new DexoptOptions(packageName, targetCompilerFilter, flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask the package manager to perform a dex-opt with the given compiler filter on the
|
||||||
|
* secondary dex files belonging to the given package.
|
||||||
|
*
|
||||||
|
* Note: exposed only for the shell command to allow moving packages explicitly to a
|
||||||
|
* definite state.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean performDexOptSecondary(String packageName, String compilerFilter,
|
||||||
|
boolean force) {
|
||||||
|
int flags = DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX |
|
||||||
|
DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES |
|
||||||
|
DexoptOptions.DEXOPT_BOOT_COMPLETE |
|
||||||
|
(force ? DexoptOptions.DEXOPT_FORCE : 0);
|
||||||
|
return performDexOpt(new DexoptOptions(packageName, compilerFilter, flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ boolean performDexOpt(DexoptOptions options) {
|
||||||
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||||
return false;
|
return false;
|
||||||
} else if (isInstantApp(packageName, UserHandle.getCallingUserId())) {
|
} else if (isInstantApp(options.getPackageName(), UserHandle.getCallingUserId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int dexoptStatus = performDexOptWithStatus(
|
|
||||||
packageName, checkProfiles, compileReason, force, bootComplete,
|
if (options.isDexoptOnlySecondaryDex()) {
|
||||||
downgrade);
|
return mDexManager.dexoptSecondaryDex(options);
|
||||||
|
} else {
|
||||||
|
int dexoptStatus = performDexOptWithStatus(options);
|
||||||
return dexoptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
|
return dexoptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform dexopt on the given package and return one of following result:
|
* Perform dexopt on the given package and return one of following result:
|
||||||
@@ -9483,34 +9518,14 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
* {@link PackageDexOptimizer#DEX_OPT_PERFORMED}
|
* {@link PackageDexOptimizer#DEX_OPT_PERFORMED}
|
||||||
* {@link PackageDexOptimizer#DEX_OPT_FAILED}
|
* {@link PackageDexOptimizer#DEX_OPT_FAILED}
|
||||||
*/
|
*/
|
||||||
/* package */ int performDexOptWithStatus(String packageName,
|
/* package */ int performDexOptWithStatus(DexoptOptions options) {
|
||||||
boolean checkProfiles, int compileReason, boolean force, boolean bootComplete,
|
return performDexOptTraced(options);
|
||||||
boolean downgrade) {
|
|
||||||
return performDexOptTraced(packageName, checkProfiles,
|
|
||||||
getCompilerFilterForReason(compileReason), force, bootComplete, downgrade);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int performDexOptTraced(DexoptOptions options) {
|
||||||
public boolean performDexOptMode(String packageName,
|
|
||||||
boolean checkProfiles, String targetCompilerFilter, boolean force,
|
|
||||||
boolean bootComplete) {
|
|
||||||
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
|
||||||
return false;
|
|
||||||
} else if (isInstantApp(packageName, UserHandle.getCallingUserId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int dexOptStatus = performDexOptTraced(packageName, checkProfiles,
|
|
||||||
targetCompilerFilter, force, bootComplete, false /* downgrade */);
|
|
||||||
return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int performDexOptTraced(String packageName,
|
|
||||||
boolean checkProfiles, String targetCompilerFilter, boolean force,
|
|
||||||
boolean bootComplete, boolean downgrade) {
|
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
|
||||||
try {
|
try {
|
||||||
return performDexOptInternal(packageName, checkProfiles,
|
return performDexOptInternal(options);
|
||||||
targetCompilerFilter, force, bootComplete, downgrade);
|
|
||||||
} finally {
|
} finally {
|
||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
}
|
}
|
||||||
@@ -9518,12 +9533,10 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
|
|
||||||
// Run dexopt on a given package. Returns true if dexopt did not fail, i.e.
|
// 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.
|
// if the package can now be considered up to date for the given filter.
|
||||||
private int performDexOptInternal(String packageName,
|
private int performDexOptInternal(DexoptOptions options) {
|
||||||
boolean checkProfiles, String targetCompilerFilter, boolean force,
|
|
||||||
boolean bootComplete, boolean downgrade) {
|
|
||||||
PackageParser.Package p;
|
PackageParser.Package p;
|
||||||
synchronized (mPackages) {
|
synchronized (mPackages) {
|
||||||
p = mPackages.get(packageName);
|
p = mPackages.get(options.getPackageName());
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
// Package could not be found. Report failure.
|
// Package could not be found. Report failure.
|
||||||
return PackageDexOptimizer.DEX_OPT_FAILED;
|
return PackageDexOptimizer.DEX_OPT_FAILED;
|
||||||
@@ -9534,8 +9547,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
long callingId = Binder.clearCallingIdentity();
|
long callingId = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
synchronized (mInstallLock) {
|
synchronized (mInstallLock) {
|
||||||
return performDexOptInternalWithDependenciesLI(p, checkProfiles,
|
return performDexOptInternalWithDependenciesLI(p, options);
|
||||||
targetCompilerFilter, force, bootComplete, downgrade);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(callingId);
|
Binder.restoreCallingIdentity(callingId);
|
||||||
@@ -9555,12 +9567,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int performDexOptInternalWithDependenciesLI(PackageParser.Package p,
|
private int performDexOptInternalWithDependenciesLI(PackageParser.Package p,
|
||||||
boolean checkProfiles, String targetCompilerFilter,
|
DexoptOptions options) {
|
||||||
boolean force, boolean bootComplete, boolean downgrade) {
|
|
||||||
// Select the dex optimizer based on the force parameter.
|
// 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
|
// Note: The force option is rarely used (cmdline input for testing, mostly), so it's OK to
|
||||||
// allocate an object here.
|
// allocate an object here.
|
||||||
PackageDexOptimizer pdo = force
|
PackageDexOptimizer pdo = options.isForce()
|
||||||
? new PackageDexOptimizer.ForcedUpdatePackageDexOptimizer(mPackageDexOptimizer)
|
? new PackageDexOptimizer.ForcedUpdatePackageDexOptimizer(mPackageDexOptimizer)
|
||||||
: mPackageDexOptimizer;
|
: mPackageDexOptimizer;
|
||||||
|
|
||||||
@@ -9577,37 +9588,14 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
for (PackageParser.Package depPackage : deps) {
|
for (PackageParser.Package depPackage : deps) {
|
||||||
// TODO: Analyze and investigate if we (should) profile libraries.
|
// TODO: Analyze and investigate if we (should) profile libraries.
|
||||||
pdo.performDexOpt(depPackage, null /* sharedLibraries */, instructionSets,
|
pdo.performDexOpt(depPackage, null /* sharedLibraries */, instructionSets,
|
||||||
false /* checkProfiles */,
|
|
||||||
targetCompilerFilter,
|
|
||||||
getOrCreateCompilerPackageStats(depPackage),
|
getOrCreateCompilerPackageStats(depPackage),
|
||||||
true /* isUsedByOtherApps */,
|
true /* isUsedByOtherApps */,
|
||||||
bootComplete,
|
options);
|
||||||
downgrade);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pdo.performDexOpt(p, p.usesLibraryFiles, instructionSets, checkProfiles,
|
return pdo.performDexOpt(p, p.usesLibraryFiles, instructionSets,
|
||||||
targetCompilerFilter, getOrCreateCompilerPackageStats(p),
|
getOrCreateCompilerPackageStats(p),
|
||||||
mDexManager.isUsedByOtherApps(p.packageName), bootComplete, downgrade);
|
mDexManager.isUsedByOtherApps(p.packageName), options);
|
||||||
}
|
|
||||||
|
|
||||||
// Performs dexopt on the used secondary dex files belonging to the given package.
|
|
||||||
// Returns true if all dex files were process successfully (which could mean either dexopt or
|
|
||||||
// skip). Returns false if any of the files caused errors.
|
|
||||||
@Override
|
|
||||||
public boolean performDexOptSecondary(String packageName, String compilerFilter,
|
|
||||||
boolean force) {
|
|
||||||
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
|
||||||
return false;
|
|
||||||
} else if (isInstantApp(packageName, UserHandle.getCallingUserId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mDexManager.dexoptSecondaryDex(packageName, compilerFilter, force,
|
|
||||||
false /* compileOnlySharedDex */, false /* downgrade */);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean performDexOptSecondary(String packageName, int compileReason,
|
|
||||||
boolean force, boolean downgrade) {
|
|
||||||
return mDexManager.dexoptSecondaryDex(packageName, compileReason, force, downgrade);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9783,11 +9771,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
|
|
||||||
// Whoever is calling forceDexOpt wants a compiled package.
|
// Whoever is calling forceDexOpt wants a compiled package.
|
||||||
// Don't use profiles since that may cause compilation to be skipped.
|
// Don't use profiles since that may cause compilation to be skipped.
|
||||||
final int res = performDexOptInternalWithDependenciesLI(pkg,
|
final int res = performDexOptInternalWithDependenciesLI(
|
||||||
false /* checkProfiles */, getDefaultCompilerFilter(),
|
pkg,
|
||||||
true /* force */,
|
new DexoptOptions(packageName,
|
||||||
true /* bootComplete */,
|
getDefaultCompilerFilter(),
|
||||||
false /* downgrade */);
|
DexoptOptions.DEXOPT_FORCE | DexoptOptions.DEXOPT_BOOT_COMPLETE));
|
||||||
|
|
||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
if (res != PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
if (res != PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
||||||
@@ -18249,13 +18237,14 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
// method because `pkg` may not be in `mPackages` yet.
|
// method because `pkg` may not be in `mPackages` yet.
|
||||||
//
|
//
|
||||||
// Also, don't fail application installs if the dexopt step fails.
|
// Also, don't fail application installs if the dexopt step fails.
|
||||||
|
DexoptOptions dexoptOptions = new DexoptOptions(pkg.packageName,
|
||||||
|
REASON_INSTALL,
|
||||||
|
DexoptOptions.DEXOPT_BOOT_COMPLETE);
|
||||||
mPackageDexOptimizer.performDexOpt(pkg, pkg.usesLibraryFiles,
|
mPackageDexOptimizer.performDexOpt(pkg, pkg.usesLibraryFiles,
|
||||||
null /* instructionSets */, false /* checkProfiles */,
|
null /* instructionSets */,
|
||||||
getCompilerFilterForReason(REASON_INSTALL),
|
|
||||||
getOrCreateCompilerPackageStats(pkg),
|
getOrCreateCompilerPackageStats(pkg),
|
||||||
mDexManager.isUsedByOtherApps(pkg.packageName),
|
mDexManager.isUsedByOtherApps(pkg.packageName),
|
||||||
true /* bootComplete */,
|
dexoptOptions);
|
||||||
false /* downgrade */);
|
|
||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -301,33 +301,21 @@ public class DexManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform dexopt on the package {@code packageName} secondary dex files.
|
* Perform dexopt on with the given {@code options} on the secondary dex files.
|
||||||
* @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, int compilerReason, boolean force,
|
public boolean dexoptSecondaryDex(DexoptOptions options) {
|
||||||
boolean downgrade) {
|
|
||||||
return dexoptSecondaryDex(packageName,
|
|
||||||
PackageManagerServiceCompilerMapping.getCompilerFilterForReason(compilerReason),
|
|
||||||
force, /* compileOnlySharedDex */ false, downgrade);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform dexopt on the package {@code packageName} secondary dex files.
|
|
||||||
* @return true if all secondary dex files were processed successfully (compiled or skipped
|
|
||||||
* because they don't need to be compiled)..
|
|
||||||
*/
|
|
||||||
public boolean dexoptSecondaryDex(String packageName, String compilerFilter, boolean force,
|
|
||||||
boolean compileOnlySharedDex, boolean downgrade) {
|
|
||||||
// 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
|
||||||
// passing the force flag through the multitude of layers.
|
// passing the force flag through the multitude of layers.
|
||||||
// Note: The force option is rarely used (cmdline input for testing, mostly), so it's OK to
|
// Note: The force option is rarely used (cmdline input for testing, mostly), so it's OK to
|
||||||
// allocate an object here.
|
// allocate an object here.
|
||||||
PackageDexOptimizer pdo = force
|
PackageDexOptimizer pdo = options.isForce()
|
||||||
? new PackageDexOptimizer.ForcedUpdatePackageDexOptimizer(mPackageDexOptimizer)
|
? new PackageDexOptimizer.ForcedUpdatePackageDexOptimizer(mPackageDexOptimizer)
|
||||||
: mPackageDexOptimizer;
|
: mPackageDexOptimizer;
|
||||||
|
String packageName = options.getPackageName();
|
||||||
PackageUseInfo useInfo = getPackageUseInfo(packageName);
|
PackageUseInfo useInfo = getPackageUseInfo(packageName);
|
||||||
if (useInfo == null || useInfo.getDexUseInfoMap().isEmpty()) {
|
if (useInfo == null || useInfo.getDexUseInfoMap().isEmpty()) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -340,7 +328,7 @@ 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()) {
|
if (options.isDexoptOnlySharedDex() && !dexUseInfo.isUsedByOtherApps()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PackageInfo pkg = null;
|
PackageInfo pkg = null;
|
||||||
@@ -362,8 +350,8 @@ public class DexManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int result = pdo.dexOptSecondaryDexPath(pkg.applicationInfo, dexPath,
|
int result = pdo.dexOptSecondaryDexPath(pkg.applicationInfo, dexPath,
|
||||||
dexUseInfo.getLoaderIsas(), compilerFilter, dexUseInfo.isUsedByOtherApps(),
|
dexUseInfo.getLoaderIsas(), options.getCompilerFilter(),
|
||||||
downgrade);
|
dexUseInfo.isUsedByOtherApps(), options.isDowngrade());
|
||||||
success = success && (result != PackageDexOptimizer.DEX_OPT_FAILED);
|
success = success && (result != PackageDexOptimizer.DEX_OPT_FAILED);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
|
|||||||
113
services/core/java/com/android/server/pm/dex/DexoptOptions.java
Normal file
113
services/core/java/com/android/server/pm/dex/DexoptOptions.java
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.server.pm.dex;
|
||||||
|
|
||||||
|
import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options used for dexopt invocations.
|
||||||
|
*/
|
||||||
|
public final class DexoptOptions {
|
||||||
|
// When set, the profiles will be checked for updates before calling dexopt. If
|
||||||
|
// the apps profiles didn't update in a meaningful way (decided by the compiler), dexopt
|
||||||
|
// will be skipped.
|
||||||
|
// Currently this only affects the optimization of primary apks. Secondary dex files
|
||||||
|
// will always check the profiles for updates.
|
||||||
|
public static final int DEXOPT_CHECK_FOR_PROFILES_UPDATES = 1 << 0;
|
||||||
|
|
||||||
|
// When set, dexopt will execute unconditionally (even if not needed).
|
||||||
|
public static final int DEXOPT_FORCE = 1 << 1;
|
||||||
|
|
||||||
|
// Whether or not the invocation of dexopt is done after the boot is completed. This is used
|
||||||
|
// in order to adjust the priority of the compilation thread.
|
||||||
|
public static final int DEXOPT_BOOT_COMPLETE = 1 << 2;
|
||||||
|
|
||||||
|
// When set, the dexopt invocation will optimize only the secondary dex files. If false, dexopt
|
||||||
|
// will only consider the primary apk.
|
||||||
|
public static final int DEXOPT_ONLY_SECONDARY_DEX = 1 << 3;
|
||||||
|
|
||||||
|
// When set, dexopt will optimize only dex files that are used by other apps.
|
||||||
|
// Currently, this flag is ignored for primary apks.
|
||||||
|
public static final int DEXOPT_ONLY_SHARED_DEX = 1 << 4;
|
||||||
|
|
||||||
|
// When set, dexopt will attempt to scale down the optimizations previously applied in order
|
||||||
|
// save disk space.
|
||||||
|
public static final int DEXOPT_DOWNGRADE = 1 << 5;
|
||||||
|
|
||||||
|
// The name of package to optimize.
|
||||||
|
private final String mPackageName;
|
||||||
|
|
||||||
|
// The intended target compiler filter. Note that dexopt might adjust the filter before the
|
||||||
|
// execution based on factors like: vmSafeMode and packageUsedByOtherApps.
|
||||||
|
private final String mCompilerFilter;
|
||||||
|
|
||||||
|
// The set of flags for the dexopt options. It's a mix of the DEXOPT_* flags.
|
||||||
|
private final int mFlags;
|
||||||
|
|
||||||
|
public DexoptOptions(String packageName, String compilerFilter, int flags) {
|
||||||
|
int validityMask =
|
||||||
|
DEXOPT_CHECK_FOR_PROFILES_UPDATES |
|
||||||
|
DEXOPT_FORCE |
|
||||||
|
DEXOPT_BOOT_COMPLETE |
|
||||||
|
DEXOPT_ONLY_SECONDARY_DEX |
|
||||||
|
DEXOPT_ONLY_SHARED_DEX |
|
||||||
|
DEXOPT_DOWNGRADE;
|
||||||
|
if ((flags & (~validityMask)) != 0) {
|
||||||
|
throw new IllegalArgumentException("Invalid flags : " + Integer.toHexString(flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
mPackageName = packageName;
|
||||||
|
mCompilerFilter = compilerFilter;
|
||||||
|
mFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DexoptOptions(String packageName, int compilerReason, int flags) {
|
||||||
|
this(packageName, getCompilerFilterForReason(compilerReason), flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return mPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCheckForProfileUpdates() {
|
||||||
|
return (mFlags & DEXOPT_CHECK_FOR_PROFILES_UPDATES) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompilerFilter() {
|
||||||
|
return mCompilerFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isForce() {
|
||||||
|
return (mFlags & DEXOPT_FORCE) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBootComplete() {
|
||||||
|
return (mFlags & DEXOPT_BOOT_COMPLETE) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDexoptOnlySecondaryDex() {
|
||||||
|
return (mFlags & DEXOPT_ONLY_SECONDARY_DEX) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDexoptOnlySharedDex() {
|
||||||
|
return (mFlags & DEXOPT_ONLY_SHARED_DEX) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDowngrade() {
|
||||||
|
return (mFlags & DEXOPT_DOWNGRADE) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.server.pm.dex;
|
||||||
|
|
||||||
|
|
||||||
|
import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
|
||||||
|
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import com.android.server.pm.PackageManagerService;
|
||||||
|
import com.android.server.pm.PackageManagerServiceCompilerMapping;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@SmallTest
|
||||||
|
public class DexoptOptionsTests {
|
||||||
|
private final static String mPackageName = "test.android.com";
|
||||||
|
private final static String mCompilerFilter =
|
||||||
|
PackageManagerServiceCompilerMapping.getDefaultCompilerFilter();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDexoptOptionsEmpty() {
|
||||||
|
DexoptOptions opt = new DexoptOptions(mPackageName, mCompilerFilter, /*flags*/ 0);
|
||||||
|
assertEquals(mPackageName, opt.getPackageName());
|
||||||
|
assertEquals(mCompilerFilter, opt.getCompilerFilter());
|
||||||
|
assertFalse(opt.isBootComplete());
|
||||||
|
assertFalse(opt.isCheckForProfileUpdates());
|
||||||
|
assertFalse(opt.isDexoptOnlySecondaryDex());
|
||||||
|
assertFalse(opt.isDexoptOnlySharedDex());
|
||||||
|
assertFalse(opt.isDowngrade());
|
||||||
|
assertFalse(opt.isForce());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDexoptOptionsFull() {
|
||||||
|
int flags =
|
||||||
|
DexoptOptions.DEXOPT_FORCE |
|
||||||
|
DexoptOptions.DEXOPT_BOOT_COMPLETE |
|
||||||
|
DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES |
|
||||||
|
DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX |
|
||||||
|
DexoptOptions.DEXOPT_ONLY_SHARED_DEX |
|
||||||
|
DexoptOptions.DEXOPT_DOWNGRADE;
|
||||||
|
|
||||||
|
DexoptOptions opt = new DexoptOptions(mPackageName, mCompilerFilter, flags);
|
||||||
|
assertEquals(mPackageName, opt.getPackageName());
|
||||||
|
assertEquals(mCompilerFilter, opt.getCompilerFilter());
|
||||||
|
assertTrue(opt.isBootComplete());
|
||||||
|
assertTrue(opt.isCheckForProfileUpdates());
|
||||||
|
assertTrue(opt.isDexoptOnlySecondaryDex());
|
||||||
|
assertTrue(opt.isDexoptOnlySharedDex());
|
||||||
|
assertTrue(opt.isDowngrade());
|
||||||
|
assertTrue(opt.isForce());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDexoptOptionsReason() {
|
||||||
|
int flags =
|
||||||
|
DexoptOptions.DEXOPT_FORCE |
|
||||||
|
DexoptOptions.DEXOPT_BOOT_COMPLETE |
|
||||||
|
DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES;
|
||||||
|
|
||||||
|
int[] reasons = new int[] {
|
||||||
|
PackageManagerService.REASON_FIRST_BOOT,
|
||||||
|
PackageManagerService.REASON_BOOT,
|
||||||
|
PackageManagerService.REASON_INSTALL,
|
||||||
|
PackageManagerService.REASON_BACKGROUND_DEXOPT,
|
||||||
|
PackageManagerService.REASON_AB_OTA,
|
||||||
|
PackageManagerService.REASON_INACTIVE_PACKAGE_DOWNGRADE};
|
||||||
|
|
||||||
|
for (int reason : reasons) {
|
||||||
|
DexoptOptions opt = new DexoptOptions(mPackageName, reason, flags);
|
||||||
|
assertEquals(mPackageName, opt.getPackageName());
|
||||||
|
assertEquals(getCompilerFilterForReason(reason), opt.getCompilerFilter());
|
||||||
|
assertTrue(opt.isBootComplete());
|
||||||
|
assertTrue(opt.isCheckForProfileUpdates());
|
||||||
|
assertFalse(opt.isDexoptOnlySecondaryDex());
|
||||||
|
assertFalse(opt.isDexoptOnlySharedDex());
|
||||||
|
assertFalse(opt.isDowngrade());
|
||||||
|
assertTrue(opt.isForce());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDexoptInvalid() {
|
||||||
|
boolean gotException = false;
|
||||||
|
try {
|
||||||
|
int invalidFlags = 999;
|
||||||
|
new DexoptOptions(mPackageName, mCompilerFilter, invalidFlags);
|
||||||
|
} catch (IllegalArgumentException ignore) {
|
||||||
|
gotException = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(gotException);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user