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

Commit 45c94c64 authored by Dennis Shen's avatar Dennis Shen
Browse files

aconfig: add a new aconfig storage file flag listing api

added a new function called list_flag_with_info to list all the flags
given all four storage files (package.map, flag.map, flag.val, flag.info).
also exported this api thru cxx interface so aconfigd can use it.

Bug: b/312444587
Test: atest -c
Change-Id: Ibbfe657b980d40e25e5e28962b930338192e2d98
parent c6e4a86b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -97,5 +97,9 @@
    }
  ],
  "postsubmit": [
    {
      // aconfig_storage file cpp integration tests
      "name": "aconfig_storage_file.test.cpp"
    }
  ]
}
+60 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ rust_defaults {
        "libtempfile",
        "libprotobuf",
        "libclap",
        "libcxx",
        "libaconfig_storage_protos",
    ],
}
@@ -77,3 +78,62 @@ cc_library {
    product_available: true,
    double_loadable: true,
}

// cxx source codegen from rust api
genrule {
    name: "libcxx_aconfig_storage_file_bridge_code",
    tools: ["cxxbridge"],
    cmd: "$(location cxxbridge) $(in) > $(out)",
    srcs: ["src/lib.rs"],
    out: ["aconfig_storage/lib.rs.cc"],
}

// cxx header codegen from rust api
genrule {
    name: "libcxx_aconfig_storage_file_bridge_header",
    tools: ["cxxbridge"],
    cmd: "$(location cxxbridge) $(in) --header > $(out)",
    srcs: ["src/lib.rs"],
    out: ["aconfig_storage/lib.rs.h"],
}

// a static cc lib based on generated code
rust_ffi_static {
    name: "libaconfig_storage_file_cxx_bridge",
    crate_name: "aconfig_storage_file_cxx_bridge",
    host_supported: true,
    vendor_available: true,
    product_available: true,
    srcs: ["src/lib.rs"],
    defaults: ["aconfig_storage_file.defaults"],
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    min_sdk_version: "29",
}

// storage file parse api cc interface
cc_library {
    name: "libaconfig_storage_file_cc",
    srcs: ["aconfig_storage_file.cpp"],
    generated_headers: [
        "cxx-bridge-header",
        "libcxx_aconfig_storage_file_bridge_header",
    ],
    generated_sources: ["libcxx_aconfig_storage_file_bridge_code"],
    whole_static_libs: ["libaconfig_storage_file_cxx_bridge"],
    export_include_dirs: ["include"],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    shared_libs: [
        "libbase",
    ],
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    min_sdk_version: "29",
    double_loadable: true,
}
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ protobuf = "3.2.0"
tempfile = "3.9.0"
thiserror = "1.0.56"
clap = { version = "4.1.8", features = ["derive"] }
cxx = "1.0"

[[bin]]
name = "aconfig-storage"
+38 −0
Original line number Diff line number Diff line
#include "rust/cxx.h"
#include "aconfig_storage/lib.rs.h"

#include "aconfig_storage/aconfig_storage_file.hpp"

using namespace android::base;

namespace aconfig_storage {

Result<std::vector<FlagValueAndInfoSummary>> list_flags_with_info(
    const std::string& package_map,
    const std::string& flag_map,
    const std::string& flag_val,
    const std::string& flag_info) {
  auto flag_list_cxx = list_flags_with_info_cxx(rust::Str(package_map.c_str()),
                                                rust::Str(flag_map.c_str()),
                                                rust::Str(flag_val.c_str()),
                                                rust::Str(flag_info.c_str()));
  if (flag_list_cxx.query_success) {
    auto flag_list = std::vector<FlagValueAndInfoSummary>();
    for (const auto& flag_cxx : flag_list_cxx.flags) {
      auto flag = FlagValueAndInfoSummary();
      flag.package_name = std::string(flag_cxx.package_name);
      flag.flag_name = std::string(flag_cxx.flag_name);
      flag.flag_value = std::string(flag_cxx.flag_value);
      flag.value_type = std::string(flag_cxx.value_type);
      flag.is_readwrite = flag_cxx.is_readwrite;
      flag.has_server_override = flag_cxx.has_server_override;
      flag.has_local_override = flag_cxx.has_local_override;
      flag_list.push_back(flag);
    }
    return flag_list;
  } else {
    return Error() << flag_list_cxx.error_message;
  }
}

} // namespace aconfig_storage
+2 −0
Original line number Diff line number Diff line
@@ -14,4 +14,6 @@ fn main() {
        .inputs(proto_files)
        .cargo_out_dir("aconfig_storage_protos")
        .run_from_script();

    let _ = cxx_build::bridge("src/lib.rs");
}
Loading