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

Commit 1e0b9a9f authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Update the command for checking groups status to list all groups when no group is passed

This will make more easier for the user to check the current status of all the groups at the same time.

Test: atest TracingTests
Flag: EXEMPT debug command handling code
Change-Id: Ia9334b059d445f04dd2a73cd9dc775271d5f1f46
parent a2a9931f
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -80,8 +80,9 @@ public class ProtoLogCommandHandler extends ShellCommand {
        pw.println("    Print this help text.");
        pw.println();
        pw.println("  groups (list | status)");
        pw.println("    list - lists all ProtoLog groups registered with ProtoLog service");
        pw.println("    status <group> - print the status of a ProtoLog group");
        pw.println("    list - Lists all ProtoLog groups registered with ProtoLog service");
        pw.println("    status <group>? - Print the status of a ProtoLog group. If no group is "
                +  "passed then it prints the status of all groups.");
        pw.println();
        pw.println("  logcat (enable | disable) <group>?");
        pw.println("    Enable or disable ProtoLog to logcat. Passing no groups to the command "
@@ -127,7 +128,17 @@ public class ProtoLogCommandHandler extends ShellCommand {
                final String group = getNextArg();

                if (group == null) {
                    pw.println("Incomplete command. Use 'cmd protolog help' for guidance.");
                    final String[] allGroups = mProtoLogConfigurationService.getGroups();
                    if (allGroups.length == 0) {
                        pw.println("No ProtoLog groups registered with ProtoLog service.");
                    } else {
                        pw.println("Status for all ProtoLog groups:");
                        for (String currentGroup : allGroups) {
                            pw.println("  " + currentGroup + ": LOG_TO_LOGCAT = "
                                    + mProtoLogConfigurationService.isLoggingToLogcat(
                                    currentGroup));
                        }
                    }
                    return 0;
                }

+22 −2
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ public class ProtoLogCommandHandlerTest {

    @Test
    public void handlesGroupStatusCommandWithNoGroups() {
        Mockito.when(mProtoLogConfigurationService.getGroups())
                .thenReturn(new String[]{"MY_GROUP", "MY_OTHER_GROUP"});
        Mockito.when(mProtoLogConfigurationService.isLoggingToLogcat("MY_GROUP")).thenReturn(true);
        Mockito.when(mProtoLogConfigurationService.isLoggingToLogcat("MY_OTHER_GROUP"))
                .thenReturn(false);
        final ProtoLogCommandHandler cmdHandler =
                new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter);

@@ -136,7 +141,22 @@ public class ProtoLogCommandHandlerTest {
                FileDescriptor.err, new String[]{"groups", "status"});

        Mockito.verify(mPrintWriter, times(1))
                .println(contains("Incomplete command"));
                .println(contains("MY_GROUP: LOG_TO_LOGCAT = true"));
        Mockito.verify(mPrintWriter, times(1))
                .println(contains("MY_OTHER_GROUP: LOG_TO_LOGCAT = false"));
    }

    @Test
    public void handlesGroupStatusCommandWithNoGroupArgumentAndNoRegisteredGroups() {
        Mockito.when(mProtoLogConfigurationService.getGroups()).thenReturn(new String[]{});
        final ProtoLogCommandHandler cmdHandler =
                new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter);

        cmdHandler.exec(mMockBinder, FileDescriptor.in, FileDescriptor.out,
                FileDescriptor.err, new String[]{"groups", "status"});

        Mockito.verify(mPrintWriter, times(1))
                .println(contains("No ProtoLog groups registered"));
    }

    @Test