Merge "init: generate apex-info-list.xml"
This commit is contained in:
commit
a657c799bf
2 changed files with 59 additions and 11 deletions
|
|
@ -130,6 +130,7 @@ cc_defaults {
|
||||||
"libpropertyinfoserializer",
|
"libpropertyinfoserializer",
|
||||||
"libpropertyinfoparser",
|
"libpropertyinfoparser",
|
||||||
"libsnapshot_init",
|
"libsnapshot_init",
|
||||||
|
"libxml2",
|
||||||
"lib_apex_manifest_proto_lite",
|
"lib_apex_manifest_proto_lite",
|
||||||
"update_metadata-protos",
|
"update_metadata-protos",
|
||||||
],
|
],
|
||||||
|
|
@ -164,6 +165,9 @@ cc_library_static {
|
||||||
"selinux_policy_version",
|
"selinux_policy_version",
|
||||||
],
|
],
|
||||||
srcs: init_common_sources + init_device_sources,
|
srcs: init_common_sources + init_device_sources,
|
||||||
|
generated_sources: [
|
||||||
|
"apex-info-list",
|
||||||
|
],
|
||||||
whole_static_libs: [
|
whole_static_libs: [
|
||||||
"libcap",
|
"libcap",
|
||||||
"com.android.sysprop.apex",
|
"com.android.sysprop.apex",
|
||||||
|
|
@ -178,6 +182,12 @@ cc_library_static {
|
||||||
target: {
|
target: {
|
||||||
recovery: {
|
recovery: {
|
||||||
cflags: ["-DRECOVERY"],
|
cflags: ["-DRECOVERY"],
|
||||||
|
exclude_static_libs: [
|
||||||
|
"libxml2",
|
||||||
|
],
|
||||||
|
exclude_generated_sources: [
|
||||||
|
"apex-info-list",
|
||||||
|
],
|
||||||
exclude_shared_libs: [
|
exclude_shared_libs: [
|
||||||
"libbinder",
|
"libbinder",
|
||||||
"libutils",
|
"libutils",
|
||||||
|
|
@ -212,6 +222,9 @@ cc_binary {
|
||||||
target: {
|
target: {
|
||||||
recovery: {
|
recovery: {
|
||||||
cflags: ["-DRECOVERY"],
|
cflags: ["-DRECOVERY"],
|
||||||
|
exclude_static_libs: [
|
||||||
|
"libxml2",
|
||||||
|
],
|
||||||
exclude_shared_libs: [
|
exclude_shared_libs: [
|
||||||
"libbinder",
|
"libbinder",
|
||||||
"libutils",
|
"libutils",
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,19 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <android-base/result.h>
|
#include <android-base/result.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
#include <apex_manifest.pb.h>
|
|
||||||
|
|
||||||
#include "util.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 android {
|
||||||
namespace init {
|
namespace init {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -106,6 +115,8 @@ static bool IsApexUpdatable() {
|
||||||
return updatable;
|
return updatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ACTIVATE_FLATTENED_APEX
|
||||||
|
|
||||||
static Result<void> MountDir(const std::string& path, const std::string& mount_path) {
|
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) {
|
if (int ret = mkdir(mount_path.c_str(), 0755); ret != 0 && errno != EEXIST) {
|
||||||
return ErrnoError() << "Could not create mount point " << mount_path;
|
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 {};
|
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";
|
const std::string manifest_path = apex_dir + "/apex_manifest.pb";
|
||||||
std::string content;
|
std::string content;
|
||||||
if (!android::base::ReadFileToString(manifest_path, &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)) {
|
if (!manifest.ParseFromString(content)) {
|
||||||
return Error() << "Can't parse manifest file: " << manifest_path;
|
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,
|
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);
|
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(from_dir.c_str()), closedir);
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -140,15 +152,16 @@ static Result<void> ActivateFlattenedApexesFrom(const std::string& from_dir,
|
||||||
if (entry->d_name[0] == '.') continue;
|
if (entry->d_name[0] == '.') continue;
|
||||||
if (entry->d_type == DT_DIR) {
|
if (entry->d_type == DT_DIR) {
|
||||||
const std::string apex_path = from_dir + "/" + entry->d_name;
|
const std::string apex_path = from_dir + "/" + entry->d_name;
|
||||||
const auto apex_name = GetApexName(apex_path);
|
const auto apex_manifest = GetApexManifest(apex_path);
|
||||||
if (!apex_name.ok()) {
|
if (!apex_manifest.ok()) {
|
||||||
LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_name.error();
|
LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_manifest.error();
|
||||||
continue;
|
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()) {
|
if (auto result = MountDir(apex_path, mount_path); !result.ok()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
on_activate(apex_path, *apex_manifest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -167,15 +180,37 @@ static bool ActivateFlattenedApexesIfPossible() {
|
||||||
"/vendor/apex",
|
"/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) {
|
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();
|
LOG(ERROR) << result.error();
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // ACTIVATE_FLATTENED_APEX
|
||||||
|
|
||||||
static android::base::unique_fd bootstrap_ns_fd;
|
static android::base::unique_fd bootstrap_ns_fd;
|
||||||
static android::base::unique_fd default_ns_fd;
|
static android::base::unique_fd default_ns_fd;
|
||||||
|
|
||||||
|
|
@ -269,9 +304,9 @@ bool SetupMountNamespaces() {
|
||||||
default_ns_fd.reset(OpenMountNamespace());
|
default_ns_fd.reset(OpenMountNamespace());
|
||||||
default_ns_id = GetMountNamespaceId();
|
default_ns_id = GetMountNamespaceId();
|
||||||
}
|
}
|
||||||
|
#ifdef ACTIVATE_FLATTENED_APEX
|
||||||
success &= ActivateFlattenedApexesIfPossible();
|
success &= ActivateFlattenedApexesIfPossible();
|
||||||
|
#endif
|
||||||
LOG(INFO) << "SetupMountNamespaces done";
|
LOG(INFO) << "SetupMountNamespaces done";
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue