summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Ioffe <ioffe@google.com>2019-05-01 09:40:47 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-05-01 09:40:47 +0000
commitc4caf569e2384383bf121b32d3b2dd7397fef1c4 (patch)
treed6e8c59965df2dde9e88c47f528f75558019d947
parent10f8054938c34e3516c9261dac03dbe88219b8cf (diff)
parente44c58a5c8faaf822d96fe07bc809943c8c72983 (diff)
downloadplatform_system_apex-c4caf569e2384383bf121b32d3b2dd7397fef1c4.tar.gz
platform_system_apex-c4caf569e2384383bf121b32d3b2dd7397fef1c4.tar.bz2
platform_system_apex-c4caf569e2384383bf121b32d3b2dd7397fef1c4.zip
Merge "Manual partial CP of https://android-review.googlesource.com/q/If1d65ca4d62786845bae8df922bc2a44e2acb31b" into qt-dev
-rw-r--r--apexd/apex_constants.h6
-rw-r--r--apexd/apex_database.cpp2
-rw-r--r--apexd/apex_file.cpp8
-rw-r--r--apexd/apex_key.cpp2
-rw-r--r--apexd/apexd.cpp32
-rw-r--r--apexd/apexservice_test.cpp3
6 files changed, 23 insertions, 30 deletions
diff --git a/apexd/apex_constants.h b/apexd/apex_constants.h
index 1352ccc3..451c9cc3 100644
--- a/apexd/apex_constants.h
+++ b/apexd/apex_constants.h
@@ -16,6 +16,9 @@
#pragma once
+#include <string>
+#include <vector>
+
namespace android {
namespace apex {
@@ -23,7 +26,8 @@ static constexpr const char* kApexDataDir = "/data/apex";
static constexpr const char* kActiveApexPackagesDataDir = "/data/apex/active";
static constexpr const char* kApexBackupDir = "/data/apex/backup";
static constexpr const char* kApexPackageSystemDir = "/system/apex";
-static constexpr const char* kApexPackageProductDir = "/product/apex";
+static const std::vector<std::string> kApexPackageBuiltinDirs = {
+ kApexPackageSystemDir, "/product/apex"};
static constexpr const char* kApexRoot = "/apex";
static constexpr const char* kStagedSessionsDir = "/data/app-staging";
diff --git a/apexd/apex_database.cpp b/apexd/apex_database.cpp
index 811d05bc..4539d5a2 100644
--- a/apexd/apex_database.cpp
+++ b/apexd/apex_database.cpp
@@ -146,7 +146,7 @@ StatusOr<inode_t> inodeFor(const std::string& path) {
inode_map scanFlattendedPackages() {
inode_map map;
- for (const auto& dir : {kApexPackageSystemDir, kApexPackageProductDir}) {
+ for (const auto& dir : kApexPackageBuiltinDirs) {
ReadDir(dir, [&](const fs::directory_entry& entry) {
const auto& path = entry.path();
if (isFlattenedApex(path)) {
diff --git a/apexd/apex_file.cpp b/apexd/apex_file.cpp
index 6ffd5c93..80e60522 100644
--- a/apexd/apex_file.cpp
+++ b/apexd/apex_file.cpp
@@ -505,8 +505,12 @@ StatusOr<std::vector<std::string>> FindApexFilesByName(const std::string& path,
}
bool isPathForBuiltinApexes(const std::string& path) {
- return StartsWith(path, kApexPackageSystemDir) ||
- StartsWith(path, kApexPackageProductDir);
+ for (const auto& dir : kApexPackageBuiltinDirs) {
+ if (StartsWith(path, dir)) {
+ return true;
+ }
+ }
+ return false;
}
} // namespace apex
diff --git a/apexd/apex_key.cpp b/apexd/apex_key.cpp
index 23d9c444..16702fe6 100644
--- a/apexd/apex_key.cpp
+++ b/apexd/apex_key.cpp
@@ -91,7 +91,7 @@ Status updateScannedApexKeys(const std::vector<KeyPair>& key_pairs) {
} // namespace
Status collectApexKeys(bool scanExternalKeys) {
- for (const auto& dir : {kApexPackageSystemDir, kApexPackageProductDir}) {
+ for (const auto& dir : kApexPackageBuiltinDirs) {
StatusOr<std::vector<KeyPair>> key_pairs =
collectEmbedddedApexKeysFromDir(dir);
if (!key_pairs.Ok()) {
diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp
index f91c77de..70d4afc1 100644
--- a/apexd/apexd.cpp
+++ b/apexd/apexd.cpp
@@ -127,7 +127,7 @@ bool isBootstrapApex(const ApexFile& apex) {
// Pre-allocate loop devices so that we don't have to wait for them
// later when actually activating APEXes.
Status preAllocateLoopDevices() {
- auto scan = FindApexes({kApexPackageSystemDir, kApexPackageProductDir});
+ auto scan = FindApexes(kApexPackageBuiltinDirs);
if (!scan.Ok()) {
return scan.ErrorStatus();
}
@@ -1246,27 +1246,13 @@ std::unordered_map<std::string, uint64_t> GetActivePackagesMap() {
std::vector<ApexFile> getFactoryPackages() {
std::vector<ApexFile> ret;
- auto all_system_factory_apex_files =
- FindApexFilesByName(kApexPackageSystemDir, /* include_dirs=*/false);
- if (!all_system_factory_apex_files.Ok()) {
- LOG(ERROR) << all_system_factory_apex_files.ErrorMessage();
- return ret;
- }
- for (const std::string& path : *all_system_factory_apex_files) {
- StatusOr<ApexFile> apex_file = ApexFile::Open(path);
- if (!apex_file.Ok()) {
- LOG(ERROR) << apex_file.ErrorMessage();
- } else {
- ret.emplace_back(std::move(*apex_file));
+ for (const auto& dir : kApexPackageBuiltinDirs) {
+ auto apex_files = FindApexFilesByName(dir, /* include_dirs=*/false);
+ if (!apex_files.Ok()) {
+ LOG(ERROR) << apex_files.ErrorMessage();
+ continue;
}
- }
-
- auto all_product_factory_apex_files =
- FindApexFilesByName(kApexPackageProductDir, /* include_dirs=*/false);
- if (!all_product_factory_apex_files.Ok()) {
- LOG(INFO) << all_product_factory_apex_files.ErrorMessage();
- } else {
- for (const std::string& path : *all_product_factory_apex_files) {
+ for (const std::string& path : *apex_files) {
StatusOr<ApexFile> apex_file = ApexFile::Open(path);
if (!apex_file.Ok()) {
LOG(ERROR) << apex_file.ErrorMessage();
@@ -1780,9 +1766,9 @@ void onStart(CheckpointInterface* checkpoint_service) {
}
}
- for (auto dir : {kApexPackageSystemDir, kApexPackageProductDir}) {
+ for (const auto& dir : kApexPackageBuiltinDirs) {
// TODO(b/123622800): if activation failed, rollback and reboot.
- status = scanPackagesDirAndActivate(dir);
+ status = scanPackagesDirAndActivate(dir.c_str());
if (!status.Ok()) {
// This should never happen. Like **really** never.
// TODO: should we kill apexd in this case?
diff --git a/apexd/apexservice_test.cpp b/apexd/apexservice_test.cpp
index a48bc9e5..f4f218c6 100644
--- a/apexd/apexservice_test.cpp
+++ b/apexd/apexservice_test.cpp
@@ -844,8 +844,7 @@ TEST_F(ApexServiceTest, GetFactoryPackages) {
ASSERT_TRUE(factoryPackages->size() > 0);
for (const ApexInfo& package : *factoryPackages) {
- ASSERT_TRUE(StartsWith(package.packagePath, kApexPackageSystemDir) ||
- StartsWith(package.packagePath, kApexPackageProductDir));
+ ASSERT_TRUE(isPathForBuiltinApexes(package.packagePath));
}
}