Parse protos in library
Bug: 342636474 Test: m Change-Id: I4934fa2332b00084f73453945d6b4743566f6e48
This commit is contained in:
@@ -39,8 +39,8 @@ rust_library {
|
|||||||
|
|
||||||
genrule {
|
genrule {
|
||||||
name: "libaconfig_java_device_paths_src",
|
name: "libaconfig_java_device_paths_src",
|
||||||
srcs: ["src/DevicePathsTemplate.java"],
|
srcs: ["src/DeviceProtosTemplate.java"],
|
||||||
out: ["DevicePaths.java"],
|
out: ["DeviceProtos.java"],
|
||||||
tool_files: ["partition_aconfig_flags_paths.txt"],
|
tool_files: ["partition_aconfig_flags_paths.txt"],
|
||||||
cmd: "sed -e '/TEMPLATE/{r$(location partition_aconfig_flags_paths.txt)' -e 'd}' $(in) > $(out)",
|
cmd: "sed -e '/TEMPLATE/{r$(location partition_aconfig_flags_paths.txt)' -e 'd}' $(in) > $(out)",
|
||||||
}
|
}
|
||||||
@@ -48,5 +48,7 @@ genrule {
|
|||||||
java_library {
|
java_library {
|
||||||
name: "aconfig_device_paths_java",
|
name: "aconfig_device_paths_java",
|
||||||
srcs: [":libaconfig_java_device_paths_src"],
|
srcs: [":libaconfig_java_device_paths_src"],
|
||||||
sdk_version: "core_current",
|
static_libs: [
|
||||||
|
"libaconfig_java_proto_nano",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package android.aconfig;
|
package android.aconfig;
|
||||||
|
|
||||||
|
import android.aconfig.nano.Aconfig.parsed_flag;
|
||||||
|
import android.aconfig.nano.Aconfig.parsed_flags;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,7 +28,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class DevicePaths {
|
public class DeviceProtos {
|
||||||
static final String[] PATHS = {
|
static final String[] PATHS = {
|
||||||
TEMPLATE
|
TEMPLATE
|
||||||
};
|
};
|
||||||
@@ -31,12 +36,35 @@ public class DevicePaths {
|
|||||||
private static final String APEX_DIR = "/apex";
|
private static final String APEX_DIR = "/apex";
|
||||||
private static final String APEX_ACONFIG_PATH_SUFFIX = "/etc/aconfig_flags.pb";
|
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.
|
* Returns the list of all on-device aconfig protos paths.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static List<String> parsedFlagsProtoPaths() {
|
private static List<String> parsedFlagsProtoPaths() {
|
||||||
ArrayList<String> paths = new ArrayList(Arrays.asList(PATHS));
|
ArrayList<String> paths = new ArrayList(Arrays.asList(PATHS));
|
||||||
|
|
||||||
File apexDirectory = new File(APEX_DIR);
|
File apexDirectory = new File(APEX_DIR);
|
Reference in New Issue
Block a user