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

Commit 80aa91cd authored by Felipe Leme's avatar Felipe Leme
Browse files

Added --user option to 'dumpsys activity service'.

This is useful for services that run on multiple users, like
CarService.

Test: adb shell dumpsys activity service --user cur com.android.car
Test: adb shell dumpsys activity service --user 0 com.android.car

Bug: 171350084

Change-Id: I6c16d2946d8b03e3f381d6bef583edca175d3647
parent 64645c04
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -4940,14 +4940,16 @@ public final class ActiveServices {
     *  - the first arg isn't the flattened component name of an existing service:
     *    dump all services whose component contains the first arg as a substring
     */
    protected boolean dumpService(FileDescriptor fd, PrintWriter pw, final String name,
    protected boolean dumpService(FileDescriptor fd, PrintWriter pw, String name, int[] users,
            String[] args, int opti, boolean dumpAll) {
        final ArrayList<ServiceRecord> services = new ArrayList<>();

        final Predicate<ServiceRecord> filter = DumpUtils.filterRecord(name);

        synchronized (mAm) {
            int[] users = mAm.mUserController.getUsers();
            if (users == null) {
                users = mAm.mUserController.getUsers();
            }

            for (int user : users) {
                ServiceMap smap = mServiceMap.get(user);
@@ -4995,8 +4997,10 @@ public final class ActiveServices {
            pw.print(r.shortInstanceName); pw.print(" ");
            pw.print(Integer.toHexString(System.identityHashCode(r)));
            pw.print(" pid=");
                    if (r.app != null) pw.println(r.app.pid);
                    else pw.println("(not running)");
            if (r.app != null) {
                pw.print(r.app.pid);
                pw.print(" user="); pw.println(r.userId);
            } else pw.println("(not running)");
            if (dumpAll) {
                r.dump(pw, innerPrefix);
            }
+14 −1
Original line number Diff line number Diff line
@@ -8663,17 +8663,30 @@ public class ActivityManagerService extends IActivityManager.Stub
            } else if ("service".equals(cmd)) {
                String[] newArgs;
                String name;
                int[] users = null;
                if (opti >= args.length) {
                    name = null;
                    newArgs = EMPTY_STRING_ARRAY;
                } else {
                    name = args[opti];
                    opti++;
                    if ("--user".equals(name) && opti < args.length) {
                        int userId = UserHandle.parseUserArg(args[opti]);
                        opti++;
                        if (userId != UserHandle.USER_ALL) {
                            if (userId == UserHandle.USER_CURRENT) {
                                userId = getCurrentUser().id;
                            }
                            users = new int[] { userId };
                        }
                        name = args[opti];
                        opti++;
                    }
                    newArgs = new String[args.length - opti];
                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
                            args.length - opti);
                }
                if (!mServices.dumpService(fd, pw, name, newArgs, 0, dumpAll)) {
                if (!mServices.dumpService(fd, pw, name, users, newArgs, 0, dumpAll)) {
                    pw.println("No services match: " + name);
                    pw.println("Use -h for help.");
                }