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

Commit 6f12acb0 authored by Ted Bauer's avatar Ted Bauer
Browse files

Parse protos in library

Bug: 342636474
Test: m
Change-Id: I4934fa2332b00084f73453945d6b4743566f6e48
parent 699f9be1
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ rust_library {

genrule {
    name: "libaconfig_java_device_paths_src",
    srcs: ["src/DevicePathsTemplate.java"],
    out: ["DevicePaths.java"],
    srcs: ["src/DeviceProtosTemplate.java"],
    out: ["DeviceProtos.java"],
    tool_files: ["partition_aconfig_flags_paths.txt"],
    cmd: "sed -e '/TEMPLATE/{r$(location partition_aconfig_flags_paths.txt)' -e 'd}' $(in) > $(out)",
}
@@ -48,5 +48,7 @@ genrule {
java_library {
    name: "aconfig_device_paths_java",
    srcs: [":libaconfig_java_device_paths_src"],
    sdk_version: "core_current",
    static_libs: [
        "libaconfig_java_proto_nano",
    ],
}
+30 −2
Original line number Diff line number Diff line
@@ -15,7 +15,12 @@
 */
package android.aconfig;

import android.aconfig.nano.Aconfig.parsed_flag;
import android.aconfig.nano.Aconfig.parsed_flags;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -23,7 +28,7 @@ import java.util.List;
/**
 * @hide
 */
public class DevicePaths {
public class DeviceProtos {
    static final String[] PATHS = {
        TEMPLATE
    };
@@ -31,12 +36,35 @@ public class DevicePaths {
    private static final String APEX_DIR = "/apex";
    private static final String APEX_ACONFIG_PATH_SUFFIX = "/etc/aconfig_flags.pb";

    /**
     * Returns a list of all on-device aconfig protos.
     *
     * May throw an exception if the protos can't be read at the call site. For
     * example, some of the protos are in the apex/ partition, which is mounted
     * somewhat late in the boot process.
     *
     * @throws IOException if we can't read one of the protos yet
     * @return a list of all on-device aconfig protos
     */
    public static List<parsed_flag> loadAndParseFlagProtos() throws IOException {
        ArrayList<parsed_flag> result = new ArrayList();

        for (String path : parsedFlagsProtoPaths()) {
            FileInputStream inputStream = new FileInputStream(path);
            parsed_flags parsedFlags = parsed_flags.parseFrom(inputStream.readAllBytes());
            for (parsed_flag flag : parsedFlags.parsedFlag) {
                result.add(flag);
            }
        }

        return result;
    }

    /**
     * Returns the list of all on-device aconfig protos paths.
     * @hide
     */
    public static List<String> parsedFlagsProtoPaths() {
    private static List<String> parsedFlagsProtoPaths() {
        ArrayList<String> paths = new ArrayList(Arrays.asList(PATHS));

        File apexDirectory = new File(APEX_DIR);