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

Commit 4907b92b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add support for provider proto dump in ActivityManager"

parents 9d3458c5 fd55a940
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -14922,6 +14922,23 @@ public class ActivityManagerService extends IActivityManager.Stub
                synchronized (this) {
                    writeBroadcastsToProtoLocked(proto);
                }
            } else if ("provider".equals(cmd)) {
                String[] newArgs;
                String name;
                if (opti >= args.length) {
                    name = null;
                    newArgs = EMPTY_STRING_ARRAY;
                } else {
                    name = args[opti];
                    opti++;
                    newArgs = new String[args.length - opti];
                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
                            args.length - opti);
                }
                if (!dumpProviderProto(fd, pw, name, newArgs)) {
                    pw.println("No providers match: " + name);
                    pw.println("Use -h for help.");
                }
            } else {
                // default option, dump everything, output is ActivityManagerServiceProto
                synchronized (this) {
@@ -16063,6 +16080,15 @@ public class ActivityManagerService extends IActivityManager.Stub
        return mProviderMap.dumpProvider(fd, pw, name, args, opti, dumpAll);
    }
    /**
     * Similar to the dumpProvider, but only dumps the first matching provider.
     * The provider is responsible for dumping as proto.
     */
    protected boolean dumpProviderProto(FileDescriptor fd, PrintWriter pw, String name,
            String[] args) {
        return mProviderMap.dumpProviderProto(fd, pw, name, args);
    }
    static class ItemMatcher {
        ArrayList<ComponentName> components;
        ArrayList<String> strings;
+35 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -322,8 +323,7 @@ public final class ProviderMap {
        return needSep;
    }

    protected boolean dumpProvider(FileDescriptor fd, PrintWriter pw, String name, String[] args,
            int opti, boolean dumpAll) {
    private ArrayList<ContentProviderRecord> getProvidersForName(String name) {
        ArrayList<ContentProviderRecord> allProviders = new ArrayList<ContentProviderRecord>();
        ArrayList<ContentProviderRecord> providers = new ArrayList<ContentProviderRecord>();

@@ -365,6 +365,12 @@ public final class ProviderMap {
                }
            }
        }
        return providers;
    }

    protected boolean dumpProvider(FileDescriptor fd, PrintWriter pw, String name, String[] args,
            int opti, boolean dumpAll) {
        ArrayList<ContentProviderRecord> providers = getProvidersForName(name);

        if (providers.size() <= 0) {
            return false;
@@ -416,6 +422,33 @@ public final class ProviderMap {
        }
    }

    /**
     * Similar to the dumpProvider, but only dumps the first matching provider.
     * The provider is responsible for dumping as proto.
     */
    protected boolean dumpProviderProto(FileDescriptor fd, PrintWriter pw, String name,
            String[] args) {
        //add back the --proto arg, which was stripped out by PriorityDump
        String[] newArgs = Arrays.copyOf(args, args.length + 1);
        newArgs[args.length] = "--proto";

        ArrayList<ContentProviderRecord> providers = getProvidersForName(name);

        if (providers.size() <= 0) {
            return false;
        }

        // Only dump the first provider, since we are dumping in proto format
        for (int i = 0; i < providers.size(); i++) {
            final ContentProviderRecord r = providers.get(i);
            if (r.proc != null && r.proc.thread != null) {
                dumpToTransferPipe(null, fd, pw, r, newArgs);
                return true;
            }
        }
        return false;
    }

    /**
     * Invokes IApplicationThread.dumpProvider() on the thread of the specified provider without
     * any meta string (e.g., provider info, indentation) written to the file descriptor.