Merge "init: generate apex-info-list.xml" am: a657c799bf
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1354547 Change-Id: I4beef3524237f39f8ef7da8ee82ab816e1bde2b0
This commit is contained in:
commit
f7cb833300
|
@ -130,6 +130,7 @@ cc_defaults {
|
|||
"libpropertyinfoserializer",
|
||||
"libpropertyinfoparser",
|
||||
"libsnapshot_init",
|
||||
"libxml2",
|
||||
"lib_apex_manifest_proto_lite",
|
||||
"update_metadata-protos",
|
||||
],
|
||||
|
@ -164,6 +165,9 @@ cc_library_static {
|
|||
"selinux_policy_version",
|
||||
],
|
||||
srcs: init_common_sources + init_device_sources,
|
||||
generated_sources: [
|
||||
"apex-info-list",
|
||||
],
|
||||
whole_static_libs: [
|
||||
"libcap",
|
||||
"com.android.sysprop.apex",
|
||||
|
@ -178,6 +182,12 @@ cc_library_static {
|
|||
target: {
|
||||
recovery: {
|
||||
cflags: ["-DRECOVERY"],
|
||||
exclude_static_libs: [
|
||||
"libxml2",
|
||||
],
|
||||
exclude_generated_sources: [
|
||||
"apex-info-list",
|
||||
],
|
||||
exclude_shared_libs: [
|
||||
"libbinder",
|
||||
"libutils",
|
||||
|
@ -212,6 +222,9 @@ cc_binary {
|
|||
target: {
|
||||
recovery: {
|
||||
cflags: ["-DRECOVERY"],
|
||||
exclude_static_libs: [
|
||||
"libxml2",
|
||||
],
|
||||
exclude_shared_libs: [
|
||||
"libbinder",
|
||||
"libutils",
|
||||
|
|
|
@ -27,10 +27,19 @@
|
|||
#include <android-base/properties.h>
|
||||
#include <android-base/result.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <apex_manifest.pb.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#ifndef RECOVERY
|
||||
#define ACTIVATE_FLATTENED_APEX 1
|
||||
#endif
|
||||
|
||||
#ifdef ACTIVATE_FLATTENED_APEX
|
||||
#include <apex_manifest.pb.h>
|
||||
#include <com_android_apex.h>
|
||||
#include <selinux/android.h>
|
||||
#endif // ACTIVATE_FLATTENED_APEX
|
||||
|
||||
namespace android {
|
||||
namespace init {
|
||||
namespace {
|
||||
|
@ -106,6 +115,8 @@ static bool IsApexUpdatable() {
|
|||
return updatable;
|
||||
}
|
||||
|
||||
#ifdef ACTIVATE_FLATTENED_APEX
|
||||
|
||||
static Result<void> MountDir(const std::string& path, const std::string& mount_path) {
|
||||
if (int ret = mkdir(mount_path.c_str(), 0755); ret != 0 && errno != EEXIST) {
|
||||
return ErrnoError() << "Could not create mount point " << mount_path;
|
||||
|
@ -116,7 +127,7 @@ static Result<void> MountDir(const std::string& path, const std::string& mount_p
|
|||
return {};
|
||||
}
|
||||
|
||||
static Result<std::string> GetApexName(const std::string& apex_dir) {
|
||||
static Result<apex::proto::ApexManifest> GetApexManifest(const std::string& apex_dir) {
|
||||
const std::string manifest_path = apex_dir + "/apex_manifest.pb";
|
||||
std::string content;
|
||||
if (!android::base::ReadFileToString(manifest_path, &content)) {
|
||||
|
@ -126,11 +137,12 @@ static Result<std::string> GetApexName(const std::string& apex_dir) {
|
|||
if (!manifest.ParseFromString(content)) {
|
||||
return Error() << "Can't parse manifest file: " << manifest_path;
|
||||
}
|
||||
return manifest.name();
|
||||
return manifest;
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
static Result<void> ActivateFlattenedApexesFrom(const std::string& from_dir,
|
||||
const std::string& to_dir) {
|
||||
const std::string& to_dir, Fn on_activate) {
|
||||
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(from_dir.c_str()), closedir);
|
||||
if (!dir) {
|
||||
return {};
|
||||
|
@ -140,15 +152,16 @@ static Result<void> ActivateFlattenedApexesFrom(const std::string& from_dir,
|
|||
if (entry->d_name[0] == '.') continue;
|
||||
if (entry->d_type == DT_DIR) {
|
||||
const std::string apex_path = from_dir + "/" + entry->d_name;
|
||||
const auto apex_name = GetApexName(apex_path);
|
||||
if (!apex_name.ok()) {
|
||||
LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_name.error();
|
||||
const auto apex_manifest = GetApexManifest(apex_path);
|
||||
if (!apex_manifest.ok()) {
|
||||
LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_manifest.error();
|
||||
continue;
|
||||
}
|
||||
const std::string mount_path = to_dir + "/" + (*apex_name);
|
||||
const std::string mount_path = to_dir + "/" + apex_manifest->name();
|
||||
if (auto result = MountDir(apex_path, mount_path); !result.ok()) {
|
||||
return result;
|
||||
}
|
||||
on_activate(apex_path, *apex_manifest);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
@ -167,15 +180,37 @@ static bool ActivateFlattenedApexesIfPossible() {
|
|||
"/vendor/apex",
|
||||
};
|
||||
|
||||
std::vector<com::android::apex::ApexInfo> apex_infos;
|
||||
auto on_activate = [&](const std::string& apex_path,
|
||||
const apex::proto::ApexManifest& apex_manifest) {
|
||||
apex_infos.emplace_back(apex_manifest.name(), apex_path, apex_path, apex_manifest.version(),
|
||||
apex_manifest.versionname(), /*isFactory=*/true, /*isActive=*/true);
|
||||
};
|
||||
|
||||
for (const auto& dir : kBuiltinDirsForApexes) {
|
||||
if (auto result = ActivateFlattenedApexesFrom(dir, kApexTop); !result.ok()) {
|
||||
if (auto result = ActivateFlattenedApexesFrom(dir, kApexTop, on_activate); !result.ok()) {
|
||||
LOG(ERROR) << result.error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream oss;
|
||||
com::android::apex::ApexInfoList apex_info_list(apex_infos);
|
||||
com::android::apex::write(oss, apex_info_list);
|
||||
const std::string kApexInfoList = kApexTop + "/apex-info-list.xml";
|
||||
if (!android::base::WriteStringToFile(oss.str(), kApexInfoList)) {
|
||||
PLOG(ERROR) << "Failed to write " << kApexInfoList;
|
||||
return false;
|
||||
}
|
||||
if (selinux_android_restorecon(kApexInfoList.c_str(), 0) != 0) {
|
||||
PLOG(ERROR) << "selinux_android_restorecon(" << kApexInfoList << ") failed";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // ACTIVATE_FLATTENED_APEX
|
||||
|
||||
static android::base::unique_fd bootstrap_ns_fd;
|
||||
static android::base::unique_fd default_ns_fd;
|
||||
|
||||
|
@ -269,9 +304,9 @@ bool SetupMountNamespaces() {
|
|||
default_ns_fd.reset(OpenMountNamespace());
|
||||
default_ns_id = GetMountNamespaceId();
|
||||
}
|
||||
|
||||
#ifdef ACTIVATE_FLATTENED_APEX
|
||||
success &= ActivateFlattenedApexesIfPossible();
|
||||
|
||||
#endif
|
||||
LOG(INFO) << "SetupMountNamespaces done";
|
||||
return success;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue