Merge "[view compilation] Add --compile-layouts flag to pm compile"
This commit is contained in:
@@ -628,4 +628,9 @@ public abstract class PackageManagerInternal {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean hasSignatureCapability(int serverUid, int clientUid,
|
public abstract boolean hasSignatureCapability(int serverUid, int clientUid,
|
||||||
@PackageParser.SigningDetails.CertCapabilities int capability);
|
@PackageParser.SigningDetails.CertCapabilities int capability);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask the package manager to compile layouts in the given package.
|
||||||
|
*/
|
||||||
|
public abstract boolean compileLayouts(String packageName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -589,6 +589,14 @@ public class Installer extends SystemService {
|
|||||||
throw new InstallerException("Invalid instruction set: " + instructionSet);
|
throw new InstallerException("Invalid instruction set: " + instructionSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean compileLayouts(String apkPath, String packageName, String outDexFile, int uid) {
|
||||||
|
try {
|
||||||
|
return mInstalld.compileLayouts(apkPath, packageName, outDexFile, uid);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class InstallerException extends Exception {
|
public static class InstallerException extends Exception {
|
||||||
public InstallerException(String detailMessage) {
|
public InstallerException(String detailMessage) {
|
||||||
super(detailMessage);
|
super(detailMessage);
|
||||||
|
|||||||
@@ -450,6 +450,9 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
private static final boolean ENABLE_FREE_CACHE_V2 =
|
private static final boolean ENABLE_FREE_CACHE_V2 =
|
||||||
SystemProperties.getBoolean("fw.free_cache_v2", true);
|
SystemProperties.getBoolean("fw.free_cache_v2", true);
|
||||||
|
|
||||||
|
private static final boolean PRECOMPILED_LAYOUT_ENABLED =
|
||||||
|
SystemProperties.getBoolean("view.precompiled_layout_enabled", false);
|
||||||
|
|
||||||
private static final int RADIO_UID = Process.PHONE_UID;
|
private static final int RADIO_UID = Process.PHONE_UID;
|
||||||
private static final int LOG_UID = Process.LOG_UID;
|
private static final int LOG_UID = Process.LOG_UID;
|
||||||
private static final int NFC_UID = Process.NFC_UID;
|
private static final int NFC_UID = Process.NFC_UID;
|
||||||
@@ -9177,6 +9180,10 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
pkgCompilationReason = PackageManagerService.REASON_BACKGROUND_DEXOPT;
|
pkgCompilationReason = PackageManagerService.REASON_BACKGROUND_DEXOPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PRECOMPILED_LAYOUT_ENABLED) {
|
||||||
|
mArtManagerService.compileLayouts(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
// checkProfiles is false to avoid merging profiles during boot which
|
// checkProfiles is false to avoid merging profiles during boot which
|
||||||
// might interfere with background compilation (b/28612421).
|
// might interfere with background compilation (b/28612421).
|
||||||
// Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will
|
// Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will
|
||||||
@@ -17739,6 +17746,13 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
&& ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0);
|
&& ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0);
|
||||||
|
|
||||||
if (performDexopt) {
|
if (performDexopt) {
|
||||||
|
// Compile the layout resources.
|
||||||
|
if (PRECOMPILED_LAYOUT_ENABLED) {
|
||||||
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "compileLayouts");
|
||||||
|
mArtManagerService.compileLayouts(pkg);
|
||||||
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
|
}
|
||||||
|
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
|
||||||
// Do not run PackageDexOptimizer through the local performDexOpt
|
// Do not run PackageDexOptimizer through the local performDexOpt
|
||||||
// method because `pkg` may not be in `mPackages` yet.
|
// method because `pkg` may not be in `mPackages` yet.
|
||||||
@@ -24483,6 +24497,21 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
|
|||||||
PackageManagerService.this.notifyPackageUseLocked(packageName, reason);
|
PackageManagerService.this.notifyPackageUseLocked(packageName, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask the package manager to compile layouts in the given package.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean compileLayouts(String packageName) {
|
||||||
|
PackageParser.Package pkg;
|
||||||
|
synchronized (mPackages) {
|
||||||
|
pkg = mPackages.get(packageName);
|
||||||
|
if (pkg == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mArtManagerService.compileLayouts(pkg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import android.content.pm.InstrumentationInfo;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageInstaller;
|
import android.content.pm.PackageInstaller;
|
||||||
import android.content.pm.PackageInstaller.SessionParams;
|
import android.content.pm.PackageInstaller.SessionParams;
|
||||||
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.content.pm.PackageItemInfo;
|
import android.content.pm.PackageItemInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
@@ -1146,6 +1147,7 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
String checkProfilesRaw = null;
|
String checkProfilesRaw = null;
|
||||||
boolean secondaryDex = false;
|
boolean secondaryDex = false;
|
||||||
String split = null;
|
String split = null;
|
||||||
|
boolean compileLayouts = false;
|
||||||
|
|
||||||
String opt;
|
String opt;
|
||||||
while ((opt = getNextOption()) != null) {
|
while ((opt = getNextOption()) != null) {
|
||||||
@@ -1165,6 +1167,9 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
case "-r":
|
case "-r":
|
||||||
compilationReason = getNextArgRequired();
|
compilationReason = getNextArgRequired();
|
||||||
break;
|
break;
|
||||||
|
case "--compile-layouts":
|
||||||
|
compileLayouts = true;
|
||||||
|
break;
|
||||||
case "--check-prof":
|
case "--check-prof":
|
||||||
checkProfilesRaw = getNextArgRequired();
|
checkProfilesRaw = getNextArgRequired();
|
||||||
break;
|
break;
|
||||||
@@ -1196,14 +1201,16 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compilerFilter != null && compilationReason != null) {
|
final boolean compilerFilterGiven = compilerFilter != null;
|
||||||
pw.println("Cannot use compilation filter (\"-m\") and compilation reason (\"-r\") " +
|
final boolean compilationReasonGiven = compilationReason != null;
|
||||||
"at the same time");
|
// Make sure exactly one of -m, -r, or --compile-layouts is given.
|
||||||
return 1;
|
if ((!compilerFilterGiven && !compilationReasonGiven && !compileLayouts)
|
||||||
}
|
|| (!compilerFilterGiven && compilationReasonGiven && compileLayouts)
|
||||||
if (compilerFilter == null && compilationReason == null) {
|
|| (compilerFilterGiven && !compilationReasonGiven && compileLayouts)
|
||||||
pw.println("Cannot run without any of compilation filter (\"-m\") and compilation " +
|
|| (compilerFilterGiven && compilationReasonGiven && !compileLayouts)
|
||||||
"reason (\"-r\") at the same time");
|
|| (compilerFilterGiven && compilationReasonGiven && compileLayouts)) {
|
||||||
|
pw.println("Must specify exactly one of compilation filter (\"-m\"), compilation " +
|
||||||
|
"reason (\"-r\"), or compile layouts (\"--compile-layouts\")");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1217,15 +1224,16 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetCompilerFilter;
|
String targetCompilerFilter = null;
|
||||||
if (compilerFilter != null) {
|
if (compilerFilterGiven) {
|
||||||
if (!DexFile.isValidCompilerFilter(compilerFilter)) {
|
if (!DexFile.isValidCompilerFilter(compilerFilter)) {
|
||||||
pw.println("Error: \"" + compilerFilter +
|
pw.println("Error: \"" + compilerFilter +
|
||||||
"\" is not a valid compilation filter.");
|
"\" is not a valid compilation filter.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
targetCompilerFilter = compilerFilter;
|
targetCompilerFilter = compilerFilter;
|
||||||
} else {
|
}
|
||||||
|
if (compilationReasonGiven) {
|
||||||
int reason = -1;
|
int reason = -1;
|
||||||
for (int i = 0; i < PackageManagerServiceCompilerMapping.REASON_STRINGS.length; i++) {
|
for (int i = 0; i < PackageManagerServiceCompilerMapping.REASON_STRINGS.length; i++) {
|
||||||
if (PackageManagerServiceCompilerMapping.REASON_STRINGS[i].equals(
|
if (PackageManagerServiceCompilerMapping.REASON_STRINGS[i].equals(
|
||||||
@@ -1267,12 +1275,19 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
pw.flush();
|
pw.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = secondaryDex
|
boolean result = true;
|
||||||
|
if (compileLayouts) {
|
||||||
|
PackageManagerInternal internal = LocalServices.getService(
|
||||||
|
PackageManagerInternal.class);
|
||||||
|
result = internal.compileLayouts(packageName);
|
||||||
|
} else {
|
||||||
|
result = secondaryDex
|
||||||
? mInterface.performDexOptSecondary(packageName,
|
? mInterface.performDexOptSecondary(packageName,
|
||||||
targetCompilerFilter, forceCompilation)
|
targetCompilerFilter, forceCompilation)
|
||||||
: mInterface.performDexOptMode(packageName,
|
: mInterface.performDexOptMode(packageName,
|
||||||
checkProfiles, targetCompilerFilter, forceCompilation,
|
checkProfiles, targetCompilerFilter, forceCompilation,
|
||||||
true /* bootComplete */, split);
|
true /* bootComplete */, split);
|
||||||
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
failedPackages.add(packageName);
|
failedPackages.add(packageName);
|
||||||
}
|
}
|
||||||
@@ -2908,6 +2923,7 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
pw.println(" --check-prof (true | false): look at profiles when doing dexopt?");
|
pw.println(" --check-prof (true | false): look at profiles when doing dexopt?");
|
||||||
pw.println(" --secondary-dex: compile app secondary dex files");
|
pw.println(" --secondary-dex: compile app secondary dex files");
|
||||||
pw.println(" --split SPLIT: compile only the given split name");
|
pw.println(" --split SPLIT: compile only the given split name");
|
||||||
|
pw.println(" --compile-layouts: compile layout resources for faster inflation");
|
||||||
pw.println("");
|
pw.println("");
|
||||||
pw.println(" force-dex-opt PACKAGE");
|
pw.println(" force-dex-opt PACKAGE");
|
||||||
pw.println(" Force immediate execution of dex opt for the given PACKAGE.");
|
pw.println(" Force immediate execution of dex opt for the given PACKAGE.");
|
||||||
|
|||||||
@@ -471,6 +471,33 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile layout resources in a given package.
|
||||||
|
*/
|
||||||
|
public boolean compileLayouts(PackageParser.Package pkg) {
|
||||||
|
try {
|
||||||
|
final String packageName = pkg.packageName;
|
||||||
|
final String apkPath = pkg.baseCodePath;
|
||||||
|
final ApplicationInfo appInfo = pkg.applicationInfo;
|
||||||
|
final String outDexFile = appInfo.dataDir + "/code_cache/compiled_view.dex";
|
||||||
|
Log.i("PackageManager", "Compiling layouts in " + packageName + " (" + apkPath +
|
||||||
|
") to " + outDexFile);
|
||||||
|
long callingId = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
|
synchronized (mInstallLock) {
|
||||||
|
return mInstaller.compileLayouts(apkPath, packageName, outDexFile,
|
||||||
|
appInfo.uid);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(callingId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
Log.e("PackageManager", "Failed to compile layouts", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the profiles names for all the package code paths (excluding resource only paths).
|
* Build the profiles names for all the package code paths (excluding resource only paths).
|
||||||
* Return the map [code path -> profile name].
|
* Return the map [code path -> profile name].
|
||||||
|
|||||||
Reference in New Issue
Block a user