From d32f7fa2697f38898c8c07459796bc823fa34666 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 30 Jul 2020 01:15:18 +0900 Subject: [PATCH] Read apex-info-file.xml to distinguish vendor apex /apex/apex-info-file.xml is the list of all apexes with preinstalled path. By looking up original paths, we can figure out if an apex is from /vendor or /system even if it is updated. Bug: 159576928 Test: build & device boots Change-Id: Ie32b10bfbdd9c1b6026c4b0fc93b57a2af6b5da5 --- Android.bp | 15 ++++++++++++++- main.cc | 18 ++++++++++-------- modules/apex.cc | 27 +++++++++++++++++++++++++-- modules/include/linkerconfig/apex.h | 3 +++ 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Android.bp b/Android.bp index 57c4816..930d6b1 100644 --- a/Android.bp +++ b/Android.bp @@ -26,7 +26,19 @@ cc_defaults { "libapexutil", "libbase", "liblog", - ], + "libxml2", + ], + target: { + host: { + static_libs: [ + "libicui18n", + "libicuuc", + ], + }, + not_windows: { + static_libs: ["libicuuc_stubdata"], + }, + }, host_supported: true, } @@ -47,6 +59,7 @@ cc_library_static { srcs: [ "modules/*.cc", ], + generated_sources: ["apex-info-list"], } cc_library_static { diff --git a/main.cc b/main.cc index 3375db0..f7dd51e 100644 --- a/main.cc +++ b/main.cc @@ -184,18 +184,20 @@ Result UpdatePermission([[maybe_unused]] const std::string& file_path) { } Context GetContext(ProgramArgs args) { - auto apex_list = android::linkerconfig::modules::ScanActiveApexes(args.root); Context ctx; - for (auto const& apex_item : apex_list) { - auto apex_info = apex_item.second; - if (apex_info.has_bin || apex_info.has_lib) { - ctx.AddApexModule(std::move(apex_info)); - } - } if (args.strict) { ctx.SetStrictMode(true); } - android::linkerconfig::contents::RegisterApexNamespaceBuilders(ctx); + if (!args.is_recovery) { + auto apex_list = android::linkerconfig::modules::ScanActiveApexes(args.root); + for (auto const& apex_item : apex_list) { + auto apex_info = apex_item.second; + if (apex_info.has_bin || apex_info.has_lib) { + ctx.AddApexModule(std::move(apex_info)); + } + } + android::linkerconfig::contents::RegisterApexNamespaceBuilders(ctx); + } return ctx; } diff --git a/modules/apex.cc b/modules/apex.cc index d9e6e47..cdb5c42 100644 --- a/modules/apex.cc +++ b/modules/apex.cc @@ -15,12 +15,19 @@ */ #include "linkerconfig/apex.h" -#include - +#include #include +#include +#include "linkerconfig/environment.h" +#include "linkerconfig/log.h" #include "linkerconfig/stringutil.h" +// include after log.h to avoid macro redefnition error +#include "com_android_apex.h" + +using android::base::StartsWith; + namespace { bool DirExists(const std::string& path) { @@ -50,9 +57,25 @@ std::map ScanActiveApexes(const std::string& root) { has_lib); apexes.emplace(manifest.name(), std::move(info)); } + + std::string info_list_file = apex_root + "/apex-info-list.xml"; + auto info_list = com::android::apex::readApexInfoList(info_list_file.c_str()); + if (info_list) { + for (const auto& info : info_list->getApexInfo()) { + apexes[info.getModuleName()].original_path = + info.getPreinstalledModulePath(); + } + } return apexes; } +bool ApexInfo::InSystem() const { + return StartsWith(original_path, "/system/apex/") || + StartsWith(original_path, "/system_ext/apex/") || + (!IsProductVndkVersionDefined() && + StartsWith(original_path, "/product/apex/")); +} + } // namespace modules } // namespace linkerconfig } // namespace android \ No newline at end of file diff --git a/modules/include/linkerconfig/apex.h b/modules/include/linkerconfig/apex.h index 387ab5b..30b407a 100644 --- a/modules/include/linkerconfig/apex.h +++ b/modules/include/linkerconfig/apex.h @@ -27,6 +27,7 @@ struct ApexInfo { std::string name; std::string namespace_name; std::string path; + std::string original_path; std::vector provide_libs; std::vector require_libs; std::vector jni_libs; @@ -49,6 +50,8 @@ struct ApexInfo { std::replace( this->namespace_name.begin(), this->namespace_name.end(), '.', '_'); } + + bool InSystem() const; }; std::map ScanActiveApexes(const std::string& root); -- 2.11.0