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

Commit 0f617ae3 authored by William Escande's avatar William Escande
Browse files

SystemServer: Add snake case flag in dumpsys

Example of the output after this CL (flag are alphabetically sorted):

```
🚩Flag dump:
        [ ]: aCoolFlag             a_cool_flag
        [ ]: anotherNiceFlag       another_nice_flag
        [■]: woawThisFlagIsEnabled woaw_this_flag_is_enabled
```

Bug: 321313362
Flag: Exempt, debug tool that is protected by a complete try catch
Test: m Bluetooth
Test: adb shell dumpsys bluetooth_manager | Then check that your flags
      are correctly displayed (and with the expected value)
Change-Id: I47547c6a228b54a7dfa41a97bb815eb614b541c7
parent 6141fe50
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -2452,12 +2453,26 @@ class BluetoothManagerService {
        }
    }

    void dumpBluetoothFlags(PrintWriter writer)
    private void dumpBluetoothFlags(PrintWriter writer)
            throws IllegalAccessException, InvocationTargetException {
        writer.println("🚩Flag dump:");

        // maxLen is used to align the flag output
        int maxLen =
                Arrays.stream(Flags.class.getDeclaredMethods())
                        .map(Method::getName)
                        .map(String::length)
                        .max(Integer::compare)
                        .get();

        String fmt = "\t%s: %-" + maxLen + "s %s";

        for (Method m : Flags.class.getDeclaredMethods()) {
            String flagStatus = ((Boolean) m.invoke(null)) ? "[■]" : "[ ]";
            writer.println("\t" + flagStatus + ": " + m.getName());
            String name = m.getName();
            String snakeCaseName =
                    name.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase(Locale.US);
            writer.println(String.format(fmt, flagStatus, name, snakeCaseName));
        }
        writer.println("");
    }