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

Commit eb32b75b authored by Yu Shan's avatar Yu Shan Committed by Android (Google) Code Review
Browse files

Merge "Add description field to meta.json file." into main

parents dfb1d75a a81a13a5
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);