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

Commit 3cf7c0a2 authored by Ted Bauer's avatar Ted Bauer
Browse files

Add a Java lib to read on-device proto paths

Bug: 337911453
Test: m aconfig_on_device_protos_java
Change-Id: Iac8d671acee070ed041927028ec80c7aa371bd61

Change-Id: I19e0e52d8de71207c9858305e6248b6251a20989
parent 64dac049
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -36,3 +36,16 @@ rust_library {
    host_supported: true,
    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"],
}
+4 −6
Original line number Diff line number Diff line
[
"/system/etc/aconfig_flags.pb",
"/system_ext/etc/aconfig_flags.pb",
"/product/etc/aconfig_flags.pb",
"/vendor/etc/aconfig_flags.pb",
]
+68 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ use std::fs;

/// Determine all paths that contain an aconfig protobuf file.
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()))
        .to_vec();
    for dir in fs::read_dir("/apex")? {