Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad63ea99 authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Installer connection support for dump_profiles" into nyc-dev am:...

Merge "Merge "Installer connection support for dump_profiles" into nyc-dev am: 7c5bcfc2 am: fc536cb8" into nyc-mr1-dev-plus-aosp
parents d73289e7 4fa0e171
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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);

    /**
+14 −3
Original line number Diff line number Diff line
@@ -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;
+5 −0
Original line number Diff line number Diff line
@@ -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);
+39 −0
Original line number Diff line number Diff line
@@ -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");
+8 −0
Original line number Diff line number Diff line
@@ -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();