Merge "Merge "Installer connection support for dump_profiles" into nyc-dev am: 7c5bcfc21a am: fc536cb862" into nyc-mr1-dev-plus-aosp

This commit is contained in:
Android Build Merger (Role)
2016-06-01 23:17:02 +00:00
committed by Android (Google) Code Review
5 changed files with 71 additions and 3 deletions

View File

@@ -482,6 +482,11 @@ interface IPackageManager {
boolean performDexOptMode(String packageName, boolean checkProfiles,
String targetCompilerFilter, boolean force);
/**
* Ask the package manager to dump profiles associated with a package.
*/
void dumpProfiles(String packageName);
void forceDexOpt(String packageName);
/**

View File

@@ -157,9 +157,7 @@ public class InstallerConnection {
sharedLibraries);
}
public boolean mergeProfiles(int uid, String pkgName) throws InstallerException {
final String[] res = execute("merge_profiles", uid, pkgName);
private boolean safeParseBooleanResult(String[] res) throws InstallerException {
if ((res == null) || (res.length != 2)) {
throw new InstallerException("Invalid size result: " + Arrays.toString(res));
}
@@ -172,6 +170,19 @@ public class InstallerConnection {
return Boolean.parseBoolean(res[1]);
}
public boolean mergeProfiles(int uid, String pkgName) throws InstallerException {
final String[] res = execute("merge_profiles", uid, pkgName);
return safeParseBooleanResult(res);
}
public boolean dumpProfiles(String gid, String packageName, String codePaths)
throws InstallerException {
final String[] res = execute("dump_profiles", gid, packageName, codePaths);
return safeParseBooleanResult(res);
}
private boolean connect() {
if (mSocket != null) {
return true;

View File

@@ -153,6 +153,11 @@ public final class Installer extends SystemService {
return mInstaller.mergeProfiles(uid, pkgName);
}
public boolean dumpProfiles(String gid, String packageName, String codePaths)
throws InstallerException {
return mInstaller.dumpProfiles(gid, packageName, codePaths);
}
public void idmap(String targetApkPath, String overlayApkPath, int uid)
throws InstallerException {
mInstaller.execute("idmap", targetApkPath, overlayApkPath, uid);

View File

@@ -7464,6 +7464,45 @@ public class PackageManagerService extends IPackageManager.Stub {
mPackageUsage.write(true);
}
@Override
public void dumpProfiles(String packageName) {
PackageParser.Package pkg;
synchronized (mPackages) {
pkg = mPackages.get(packageName);
if (pkg == null) {
throw new IllegalArgumentException("Unknown package: " + packageName);
}
}
/* Only the shell or the app user should be able to dump profiles. */
int callingUid = Binder.getCallingUid();
if (callingUid != Process.SHELL_UID && callingUid != pkg.applicationInfo.uid) {
throw new SecurityException("dumpProfiles");
}
synchronized (mInstallLock) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dump profiles");
final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
try {
final File codeFile = new File(pkg.applicationInfo.getCodePath());
List<String> allCodePaths = Collections.EMPTY_LIST;
if (codeFile != null && codeFile.exists()) {
try {
final PackageLite codePkg = PackageParser.parsePackageLite(codeFile, 0);
allCodePaths = codePkg.getAllCodePaths();
} catch (PackageParserException e) {
// Well, we tried.
}
}
String gid = Integer.toString(sharedGid);
String codePaths = TextUtils.join(";", allCodePaths);
mInstaller.dumpProfiles(gid, packageName, codePaths);
} catch (InstallerException e) {
Slog.w(TAG, "Failed to dump profiles", e);
}
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
}
}
@Override
public void forceDexOpt(String packageName) {
enforceSystemOrRoot("forceDexOpt");

View File

@@ -105,6 +105,8 @@ class PackageManagerShellCommand extends ShellCommand {
return runInstallWrite();
case "compile":
return runCompile();
case "dump-profiles":
return runDumpProfiles();
case "list":
return runList();
case "uninstall":
@@ -387,6 +389,12 @@ class PackageManagerShellCommand extends ShellCommand {
}
}
private int runDumpProfiles() throws RemoteException {
String packageName = getNextArg();
mInterface.dumpProfiles(packageName);
return 0;
}
private int runList() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
final String type = getNextArg();