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

Commit a81a13a5 authored by Yu Shan's avatar Yu Shan
Browse files

Add description field to meta.json file.

This allows emulator to show the detailed desription for each
VHAL property by hovering on the property name.

Test: Manually inspect the JSON file.
Bug: 324486041
Change-Id: Ie07dc055d30ae9b84641f952401871348141b398
parent d3753ec9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
DisableFormat: true
+532 −266

File changed.

Preview size limit exceeded, changes collapsed.

+33 −4
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ public final class EmuMetadataGenerator {
    private static final String CHECK_FILE_PATH =
            "${ANDROID_BUILD_TOP}/hardware/interfaces/automotive/vehicle/aidl/emu_metadata/"
            + "android.hardware.automotive.vehicle-types-meta.json";
    private static final List<String> ANNOTATIONS =
            List.of("@change_mode", "@access", "@version", "@data_enum", "@unit");

    // Emulator can display at least this many characters before cutting characters.
    private static final int MAX_PROPERTY_NAME_LENGTH = 30;
@@ -141,6 +143,7 @@ public final class EmuMetadataGenerator {
        public String name;
        public Integer value;
        public final List<String> dataEnums = new ArrayList<>();
        public String description = "";

        ValueField(String name, Integer value) {
            this.name = name;
@@ -313,14 +316,36 @@ public final class EmuMetadataGenerator {

            int propertyId = parseIntEnumField(propertyDef);
            // We use the first paragraph as the property's name
            String propertyDescription = doc.getDescription().toText().split("\n\n")[0];
            String name = propertyDescription;
            if (propertyDescription.indexOf("\n") != -1
                    || propertyDescription.length() > MAX_PROPERTY_NAME_LENGTH) {
            String propertyDescription = doc.getDescription().toText();
            String firstLine = propertyDescription.split("\n\n")[0];
            String name = firstLine;
            if (firstLine.indexOf("\n") != -1 || firstLine.length() > MAX_PROPERTY_NAME_LENGTH) {
                // The description is too long, we just use the property name.
                name = propertyName;
            }

            ValueField field = new ValueField(name, propertyId);
            String fieldDescription = "";
            for (String line : propertyDescription.split("\n")) {
                String stripped = line.strip();
                // If this is an empty line, starts a new paragraph.
                if (stripped.isEmpty()) {
                    fieldDescription += "\n";
                }
                // Ignore annotation lines.
                for (int j = 0; j < ANNOTATIONS.size(); j++) {
                    if (stripped.startsWith(ANNOTATIONS.get(j))) {
                        continue;
                    }
                }
                // If this is a new line, we concat it with the previous line with a space.
                if (!fieldDescription.isEmpty()
                        && fieldDescription.charAt(fieldDescription.length() - 1) != '\n') {
                    fieldDescription += " ";
                }
                fieldDescription += stripped;
            }
            field.description = fieldDescription.strip();

            List<JavadocBlockTag> blockTags = doc.getBlockTags();
            for (int j = 0; j < blockTags.size(); j++) {
@@ -381,6 +406,9 @@ public final class EmuMetadataGenerator {
                    // entry.
                    jsonValueField.put("data_enum", valueField.dataEnums.get(0));
                }
                if (!valueField.description.isEmpty()) {
                    jsonValueField.put("description", valueField.description);
                }
                values.put(jsonValueField);
            }

@@ -390,6 +418,7 @@ public final class EmuMetadataGenerator {
        try (FileOutputStream outputStream = new FileOutputStream(parsedArgs.output)) {
            outputStream.write(jsonEnums.toString(4).getBytes());
        }

        System.out.println("Input at folder: " + parsedArgs.inputDir
                + " successfully parsed. Output at: " + parsedArgs.output);