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

Commit 0a06858b authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add "dump all components" option to dumpsys package p

"dumpsys package --all-components PACKAGE-NAME" now dumps activities/
services/receivers/instrumentation component names.

Bug: 110088132
Test: dumpsys package --all-components com.google.android.dialer
Test: dumpsys package --all-components com.android.providers.contacts
Test: dumpsys package --all-components android.content.pm.cts.shortcutmanager
Change-Id: I639ab8b3cf2154c67c547ed2c239706700d184b5
parent 8a3d990e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public final class DumpState {
    public static final int DUMP_SERVICE_PERMISSIONS = 1 << 24;

    public static final int OPTION_SHOW_FILTERS = 1 << 0;
    public static final int OPTION_DUMP_ALL_COMPONENTS = 1 << 1;

    private int mTypes;

+4 −1
Original line number Diff line number Diff line
@@ -21324,10 +21324,11 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
                // Right now we only know how to print all.
            } else if ("-h".equals(opt)) {
                pw.println("Package manager dump options:");
                pw.println("  [-h] [-f] [--checkin] [cmd] ...");
                pw.println("  [-h] [-f] [--checkin] [--all-components] [cmd] ...");
                pw.println("    --checkin: dump for a checkin");
                pw.println("    -f: print details of intent filters");
                pw.println("    -h: print this help");
                pw.println("    --all-components: include all component names in package dump");
                pw.println("  cmd may be one of:");
                pw.println("    l[ibraries]: list known shared libraries");
                pw.println("    f[eatures]: list device features");
@@ -21355,6 +21356,8 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
                return;
            } else if ("--checkin".equals(opt)) {
                checkin = true;
            } else if ("--all-components".equals(opt)) {
                dumpState.setOptionEnabled(DumpState.OPTION_DUMP_ALL_COMPONENTS);
            } else if ("-f".equals(opt)) {
                dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
            } else if ("--proto".equals(opt)) {
+32 −3
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.JournaledFile;
@@ -4471,7 +4472,7 @@ public final class Settings {

    void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag,
            ArraySet<String> permissionNames, PackageSetting ps, SimpleDateFormat sdf,
            Date date, List<UserInfo> users, boolean dumpAll) {
            Date date, List<UserInfo> users, boolean dumpAll, boolean dumpAllComponents) {
        if (checkinTag != null) {
            pw.print(checkinTag);
            pw.print(",");
@@ -4756,6 +4757,10 @@ public final class Settings {
            dumpInstallPermissionsLPr(pw, prefix + "  ", permissionNames, permissionsState);
        }

        if (dumpAllComponents) {
            dumpComponents(pw, prefix + "  ", ps);
        }

        for (UserInfo user : users) {
            pw.print(prefix); pw.print("  User "); pw.print(user.id); pw.print(": ");
            pw.print("ceDataInode=");
@@ -4835,6 +4840,8 @@ public final class Settings {
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        final Date date = new Date();
        boolean printedSomething = false;
        final boolean dumpAllComponents =
                dumpState.isOptionEnabled(DumpState.OPTION_DUMP_ALL_COMPONENTS);
        List<UserInfo> users = getAllUsers(UserManagerService.getInstance());
        for (final PackageSetting ps : mPackages.values()) {
            if (packageName != null && !packageName.equals(ps.realName)
@@ -4857,7 +4864,7 @@ public final class Settings {
                printedSomething = true;
            }
            dumpPackageLPr(pw, "  ", checkin ? "pkg" : null, permissionNames, ps, sdf, date, users,
                    packageName != null);
                    packageName != null, dumpAllComponents);
        }

        printedSomething = false;
@@ -4898,7 +4905,7 @@ public final class Settings {
                    printedSomething = true;
                }
                dumpPackageLPr(pw, "  ", checkin ? "dis" : null, permissionNames, ps, sdf, date,
                        users, packageName != null);
                        users, packageName != null, dumpAllComponents);
            }
        }
    }
@@ -5107,6 +5114,28 @@ public final class Settings {
        }
    }

    void dumpComponents(PrintWriter pw, String prefix, PackageSetting ps) {
        dumpComponents(pw, prefix, ps, "activities:", ps.pkg.activities);
        dumpComponents(pw, prefix, ps, "services:", ps.pkg.services);
        dumpComponents(pw, prefix, ps, "receivers:", ps.pkg.receivers);
        dumpComponents(pw, prefix, ps, "providers:", ps.pkg.providers);
        dumpComponents(pw, prefix, ps, "instrumentations:", ps.pkg.instrumentation);
    }

    void dumpComponents(PrintWriter pw, String prefix, PackageSetting ps,
            String label, List<? extends PackageParser.Component<?>> list) {
        final int size = CollectionUtils.size(list);
        if (size == 0) {
            return;
        }
        pw.print(prefix);pw.println(label);
        for (int i = 0; i < size; i++) {
            final PackageParser.Component<?> component = list.get(i);
            pw.print(prefix);pw.print("  ");
            pw.println(component.getComponentName().flattenToShortString());
        }
    }

    public void writeRuntimePermissionsForUserLPr(int userId, boolean sync) {
        if (sync) {
            mRuntimePermissionsPersistence.writePermissionsForUserSyncLPr(userId);