Merge "Add a Java lib to read on-device proto paths" into main

This commit is contained in:
Treehugger Robot
2024-05-09 15:05:28 +00:00
committed by Gerrit Code Review
4 changed files with 86 additions and 7 deletions

View File

@@ -36,3 +36,16 @@ rust_library {
host_supported: true, host_supported: true,
defaults: ["libaconfig_device_paths.defaults"], defaults: ["libaconfig_device_paths.defaults"],
} }
genrule {
name: "libaconfig_java_device_paths_src",
srcs: ["src/DevicePathsTemplate.java"],
out: ["DevicePaths.java"],
tool_files: ["partition_aconfig_flags_paths.txt"],
cmd: "sed -e '/TEMPLATE/{r$(location partition_aconfig_flags_paths.txt)' -e 'd}' $(in) > $(out)"
}
java_library {
name: "aconfig_device_paths_java",
srcs: [":libaconfig_java_device_paths_src"],
}

View File

@@ -1,6 +1,4 @@
[ "/system/etc/aconfig_flags.pb",
"/system/etc/aconfig_flags.pb", "/system_ext/etc/aconfig_flags.pb",
"/system_ext/etc/aconfig_flags.pb", "/product/etc/aconfig_flags.pb",
"/product/etc/aconfig_flags.pb", "/vendor/etc/aconfig_flags.pb",
"/vendor/etc/aconfig_flags.pb",
]

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.aconfig;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @hide
*/
public class DevicePaths {
static final String[] PATHS = {
TEMPLATE
};
private static final String APEX_DIR = "/apex";
private static final String APEX_ACONFIG_PATH_SUFFIX = "/etc/aconfig_flags.pb";
/**
* Returns the list of all on-device aconfig protos paths.
* @hide
*/
public List<String> parsedFlagsProtoPaths() {
ArrayList<String> paths = new ArrayList(Arrays.asList(PATHS));
File apexDirectory = new File(APEX_DIR);
if (!apexDirectory.isDirectory()) {
return paths;
}
File[] subdirs = apexDirectory.listFiles();
if (subdirs == null) {
return paths;
}
for (File prefix : subdirs) {
// For each mainline modules, there are two directories, one <modulepackage>/,
// and one <modulepackage>@<versioncode>/. Just read the former.
if (prefix.getAbsolutePath().contains("@")) {
continue;
}
File protoPath = new File(prefix + APEX_ACONFIG_PATH_SUFFIX);
if (!protoPath.exists()) {
continue;
}
paths.add(protoPath.getAbsolutePath());
}
return paths;
}
}

View File

@@ -23,7 +23,7 @@ use std::fs;
/// Determine all paths that contain an aconfig protobuf file. /// Determine all paths that contain an aconfig protobuf file.
pub fn parsed_flags_proto_paths() -> Result<Vec<PathBuf>> { pub fn parsed_flags_proto_paths() -> Result<Vec<PathBuf>> {
let mut result: Vec<PathBuf> = include!("../partition_aconfig_flags_paths.txt") let mut result: Vec<PathBuf> = [include_str!("../partition_aconfig_flags_paths.txt")]
.map(|s| PathBuf::from(s.to_string())) .map(|s| PathBuf::from(s.to_string()))
.to_vec(); .to_vec();
for dir in fs::read_dir("/apex")? { for dir in fs::read_dir("/apex")? {