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

Commit fd55a940 authored by Steven Timotius's avatar Steven Timotius
Browse files

Add support for provider proto dump in ActivityManager

The provider dump will only support 1 provider,
since protos can only be output one at a time anyways.

This is a regression from OCMR1.

Test requires change to LauncherProvider to not require the
--proto arg to be first.

Bug: 69006241
Test: adb shell dumpsys activity provider com.google.android.apps.nexuslauncher/com.android.launcher3.LauncherProvider --proto -debug
Change-Id: I5759a305c7f9456fb2ed9deb60e39b8e0e6edf78
parent ae5eb83a
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -14925,6 +14925,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) {
@@ -16066,6 +16083,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.