Merge "Remove module_test_utils completely"
diff --git a/apexd/aidl/android/apex/IApexService.aidl b/apexd/aidl/android/apex/IApexService.aidl
index 4d9b5f7..57adcf8 100644
--- a/apexd/aidl/android/apex/IApexService.aidl
+++ b/apexd/aidl/android/apex/IApexService.aidl
@@ -36,9 +36,9 @@
/**
* Copies the CE apex data directory for the given user to the backup
- * location, and returns the inode of the snapshot directory.
+ * location.
*/
- long snapshotCeData(int user_id, int rollback_id, in @utf8InCpp String apex_name);
+ void snapshotCeData(int user_id, int rollback_id, in @utf8InCpp String apex_name);
/**
* Restores the snapshot of the CE apex data directory for the given user and
@@ -52,6 +52,11 @@
void destroyDeSnapshots(int rollback_id);
/**
+ * Deletes credential-encrypted snapshots for the given user, for the given rollback id.
+ */
+ void destroyCeSnapshots(int user_id, int rollback_id);
+
+ /**
* Deletes all credential-encrypted snapshots for the given user, except for
* those listed in retain_rollback_ids.
*/
diff --git a/apexd/apex_database.cpp b/apexd/apex_database.cpp
index 13a5472..0f9502c 100644
--- a/apexd/apex_database.cpp
+++ b/apexd/apex_database.cpp
@@ -77,12 +77,12 @@
fs::path DevPath() const { return kDevBlock / name; }
Result<std::string> GetProperty(const std::string& property) const {
- auto propertyFile = SysPath() / property;
- std::string propertyValue;
- if (!ReadFileToString(propertyFile, &propertyValue)) {
+ auto property_file = SysPath() / property;
+ std::string property_value;
+ if (!ReadFileToString(property_file, &property_value)) {
return ErrnoError() << "Fail to read";
}
- return Trim(propertyValue);
+ return Trim(property_value);
}
std::vector<BlockDevice> GetSlaves() const {
@@ -101,17 +101,17 @@
}
};
-std::pair<fs::path, fs::path> parseMountInfo(const std::string& mountInfo) {
- const auto& tokens = Split(mountInfo, " ");
+std::pair<fs::path, fs::path> ParseMountInfo(const std::string& mount_info) {
+ const auto& tokens = Split(mount_info, " ");
if (tokens.size() < 2) {
return std::make_pair("", "");
}
return std::make_pair(tokens[0], tokens[1]);
}
-std::pair<std::string, int> parseMountPoint(const std::string& mountPoint) {
- auto packageId = fs::path(mountPoint).filename();
- auto split = Split(packageId, "@");
+std::pair<std::string, int> ParseMountPoint(const std::string& mount_point) {
+ auto package_id = fs::path(mount_point).filename();
+ auto split = Split(package_id, "@");
if (split.size() == 2) {
int version;
if (!ParseInt(split[1], &version)) {
@@ -119,11 +119,11 @@
}
return std::make_pair(split[0], version);
}
- return std::make_pair(packageId, -1);
+ return std::make_pair(package_id, -1);
}
-bool isActiveMountPoint(const std::string& mountPoint) {
- return (mountPoint.find('@') == std::string::npos);
+bool IsActiveMountPoint(const std::string& mount_point) {
+ return (mount_point.find('@') == std::string::npos);
}
Result<void> PopulateLoopInfo(const BlockDevice& top_device,
@@ -189,17 +189,17 @@
apex_data->full_path = full_path;
}
-Result<MountedApexData> resolveMountInfo(const BlockDevice& block,
- const std::string& mountPoint) {
- bool temp_mount = EndsWith(mountPoint, ".tmp");
+Result<MountedApexData> ResolveMountInfo(const BlockDevice& block,
+ const std::string& mount_point) {
+ bool temp_mount = EndsWith(mount_point, ".tmp");
// Now, see if it is dm-verity or loop mounted
switch (block.GetType()) {
case LoopDevice: {
- auto backingFile = block.GetProperty("loop/backing_file");
- if (!backingFile.ok()) {
- return backingFile.error();
+ auto backing_file = block.GetProperty("loop/backing_file");
+ if (!backing_file.ok()) {
+ return backing_file.error();
}
- auto result = MountedApexData(block.DevPath(), *backingFile, mountPoint,
+ auto result = MountedApexData(block.DevPath(), *backing_file, mount_point,
/* device_name= */ "",
/* hashtree_loop_name= */ "",
/* is_temp_mount */ temp_mount);
@@ -212,7 +212,7 @@
return name.error();
}
MountedApexData result;
- result.mount_point = mountPoint;
+ result.mount_point = mount_point;
result.device_name = *name;
result.is_temp_mount = temp_mount;
if (auto status = PopulateLoopInfo(block, &result); !status.ok()) {
@@ -253,37 +253,37 @@
void MountedApexDatabase::PopulateFromMounts() {
LOG(INFO) << "Populating APEX database from mounts...";
- std::unordered_map<std::string, int> activeVersions;
+ std::unordered_map<std::string, int> active_versions;
std::ifstream mounts("/proc/mounts");
std::string line;
while (std::getline(mounts, line)) {
- auto [block, mountPoint] = parseMountInfo(line);
+ auto [block, mount_point] = ParseMountInfo(line);
// TODO(b/158469914): distinguish between temp and non-temp mounts
- if (fs::path(mountPoint).parent_path() != kApexRoot) {
+ if (fs::path(mount_point).parent_path() != kApexRoot) {
continue;
}
- if (isActiveMountPoint(mountPoint)) {
+ if (IsActiveMountPoint(mount_point)) {
continue;
}
- auto mountData = resolveMountInfo(BlockDevice(block), mountPoint);
- if (!mountData.ok()) {
- LOG(WARNING) << "Can't resolve mount info " << mountData.error();
+ auto mount_data = ResolveMountInfo(BlockDevice(block), mount_point);
+ if (!mount_data.ok()) {
+ LOG(WARNING) << "Can't resolve mount info " << mount_data.error();
continue;
}
- auto [package, version] = parseMountPoint(mountPoint);
- AddMountedApex(package, false, *mountData);
+ auto [package, version] = ParseMountPoint(mount_point);
+ AddMountedApex(package, false, *mount_data);
- auto active = activeVersions[package] < version;
+ auto active = active_versions[package] < version;
if (active) {
- activeVersions[package] = version;
- SetLatest(package, mountData->full_path);
+ active_versions[package] = version;
+ SetLatest(package, mount_data->full_path);
}
- LOG(INFO) << "Found " << mountPoint << " backed by"
- << (mountData->deleted ? " deleted " : " ") << "file "
- << mountData->full_path;
+ LOG(INFO) << "Found " << mount_point << " backed by"
+ << (mount_data->deleted ? " deleted " : " ") << "file "
+ << mount_data->full_path;
}
LOG(INFO) << mounted_apexes_.size() << " packages restored.";
diff --git a/apexd/apex_file.cpp b/apexd/apex_file.cpp
index 83264d3..2049ff9 100644
--- a/apexd/apex_file.cpp
+++ b/apexd/apex_file.cpp
@@ -153,7 +153,7 @@
static constexpr int kVbMetaMaxSize = 64 * 1024;
-std::string bytes_to_hex(const uint8_t* bytes, size_t bytes_len) {
+std::string BytesToHex(const uint8_t* bytes, size_t bytes_len) {
std::ostringstream s;
s << std::hex << std::setfill('0');
@@ -163,22 +163,22 @@
return s.str();
}
-std::string getSalt(const AvbHashtreeDescriptor& desc,
- const uint8_t* trailingData) {
- const uint8_t* desc_salt = trailingData + desc.partition_name_len;
+std::string GetSalt(const AvbHashtreeDescriptor& desc,
+ const uint8_t* trailing_data) {
+ const uint8_t* desc_salt = trailing_data + desc.partition_name_len;
- return bytes_to_hex(desc_salt, desc.salt_len);
+ return BytesToHex(desc_salt, desc.salt_len);
}
-std::string getDigest(const AvbHashtreeDescriptor& desc,
- const uint8_t* trailingData) {
+std::string GetDigest(const AvbHashtreeDescriptor& desc,
+ const uint8_t* trailing_data) {
const uint8_t* desc_digest =
- trailingData + desc.partition_name_len + desc.salt_len;
+ trailing_data + desc.partition_name_len + desc.salt_len;
- return bytes_to_hex(desc_digest, desc.root_digest_len);
+ return BytesToHex(desc_digest, desc.root_digest_len);
}
-Result<std::unique_ptr<AvbFooter>> getAvbFooter(const ApexFile& apex,
+Result<std::unique_ptr<AvbFooter>> GetAvbFooter(const ApexFile& apex,
const unique_fd& fd) {
std::array<uint8_t, AVB_FOOTER_SIZE> footer_data;
auto footer = std::make_unique<AvbFooter>();
@@ -211,7 +211,7 @@
}
// Verifies correctness of vbmeta and returns public key it was signed with.
-Result<std::span<const uint8_t>> verifyVbMetaSignature(const ApexFile& apex,
+Result<std::span<const uint8_t>> VerifyVbMetaSignature(const ApexFile& apex,
const uint8_t* data,
size_t length) {
const uint8_t* pk;
@@ -240,7 +240,7 @@
return std::span<const uint8_t>(pk, pk_len);
}
-Result<std::unique_ptr<uint8_t[]>> verifyVbMeta(const ApexFile& apex,
+Result<std::unique_ptr<uint8_t[]>> VerifyVbMeta(const ApexFile& apex,
const unique_fd& fd,
const AvbFooter& footer,
const std::string& public_key) {
@@ -256,7 +256,7 @@
}
Result<std::span<const uint8_t>> st =
- verifyVbMetaSignature(apex, vbmeta_buf.get(), footer.vbmeta_size);
+ VerifyVbMetaSignature(apex, vbmeta_buf.get(), footer.vbmeta_size);
if (!st.ok()) {
return st.error();
}
@@ -269,7 +269,7 @@
return vbmeta_buf;
}
-Result<const AvbHashtreeDescriptor*> findDescriptor(uint8_t* vbmeta_data,
+Result<const AvbHashtreeDescriptor*> FindDescriptor(uint8_t* vbmeta_data,
size_t vbmeta_size) {
const AvbDescriptor** descriptors;
size_t num_descriptors;
@@ -303,62 +303,62 @@
return Errorf("Couldn't find any AVB hashtree descriptors.");
}
-Result<std::unique_ptr<AvbHashtreeDescriptor>> verifyDescriptor(
+Result<std::unique_ptr<AvbHashtreeDescriptor>> VerifyDescriptor(
const AvbHashtreeDescriptor* desc) {
- auto verifiedDesc = std::make_unique<AvbHashtreeDescriptor>();
+ auto verified_desc = std::make_unique<AvbHashtreeDescriptor>();
if (!avb_hashtree_descriptor_validate_and_byteswap(desc,
- verifiedDesc.get())) {
+ verified_desc.get())) {
return Errorf("Couldn't validate AvbDescriptor.");
}
- return verifiedDesc;
+ return verified_desc;
}
} // namespace
Result<ApexVerityData> ApexFile::VerifyApexVerity(
const std::string& public_key) const {
- ApexVerityData verityData;
+ ApexVerityData verity_data;
unique_fd fd(open(GetPath().c_str(), O_RDONLY | O_CLOEXEC));
if (fd.get() == -1) {
return ErrnoError() << "Failed to open " << GetPath();
}
- Result<std::unique_ptr<AvbFooter>> footer = getAvbFooter(*this, fd);
+ Result<std::unique_ptr<AvbFooter>> footer = GetAvbFooter(*this, fd);
if (!footer.ok()) {
return footer.error();
}
Result<std::unique_ptr<uint8_t[]>> vbmeta_data =
- verifyVbMeta(*this, fd, **footer, public_key);
+ VerifyVbMeta(*this, fd, **footer, public_key);
if (!vbmeta_data.ok()) {
return vbmeta_data.error();
}
Result<const AvbHashtreeDescriptor*> descriptor =
- findDescriptor(vbmeta_data->get(), (*footer)->vbmeta_size);
+ FindDescriptor(vbmeta_data->get(), (*footer)->vbmeta_size);
if (!descriptor.ok()) {
return descriptor.error();
}
- Result<std::unique_ptr<AvbHashtreeDescriptor>> verifiedDescriptor =
- verifyDescriptor(*descriptor);
- if (!verifiedDescriptor.ok()) {
- return verifiedDescriptor.error();
+ Result<std::unique_ptr<AvbHashtreeDescriptor>> verified_descriptor =
+ VerifyDescriptor(*descriptor);
+ if (!verified_descriptor.ok()) {
+ return verified_descriptor.error();
}
- verityData.desc = std::move(*verifiedDescriptor);
+ verity_data.desc = std::move(*verified_descriptor);
// This area is now safe to access, because we just verified it
- const uint8_t* trailingData =
+ const uint8_t* trailing_data =
(const uint8_t*)*descriptor + sizeof(AvbHashtreeDescriptor);
- verityData.hash_algorithm =
+ verity_data.hash_algorithm =
reinterpret_cast<const char*>((*descriptor)->hash_algorithm);
- verityData.salt = getSalt(*verityData.desc, trailingData);
- verityData.root_digest = getDigest(*verityData.desc, trailingData);
+ verity_data.salt = GetSalt(*verity_data.desc, trailing_data);
+ verity_data.root_digest = GetDigest(*verity_data.desc, trailing_data);
- return verityData;
+ return verity_data;
}
} // namespace apex
diff --git a/apexd/apex_file_test.cpp b/apexd/apex_file_test.cpp
index 2cf7d5d..f575434 100644
--- a/apexd/apex_file_test.cpp
+++ b/apexd/apex_file_test.cpp
@@ -27,9 +27,10 @@
#include "apex_file.h"
+using android::base::GetExecutableDirectory;
using android::base::Result;
-static std::string testDataDir = android::base::GetExecutableDirectory() + "/";
+static const std::string kTestDataDir = GetExecutableDirectory() + "/";
namespace android {
namespace apex {
@@ -48,15 +49,15 @@
INSTANTIATE_TEST_SUITE_P(Apex, ApexFileTest, testing::ValuesIn(kParameters));
TEST_P(ApexFileTest, GetOffsetOfSimplePackage) {
- const std::string filePath = testDataDir + GetParam().prefix + ".apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_TRUE(apexFile.ok());
+ const std::string file_path = kTestDataDir + GetParam().prefix + ".apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_TRUE(apex_file.ok());
int32_t zip_image_offset;
size_t zip_image_size;
{
ZipArchiveHandle handle;
- int32_t rc = OpenArchive(filePath.c_str(), &handle);
+ int32_t rc = OpenArchive(file_path.c_str(), &handle);
ASSERT_EQ(0, rc);
auto close_guard =
android::base::make_scope_guard([&handle]() { CloseArchive(handle); });
@@ -71,32 +72,33 @@
EXPECT_EQ(zip_image_size, entry.compressed_length);
}
- EXPECT_EQ(zip_image_offset, apexFile->GetImageOffset());
- EXPECT_EQ(zip_image_size, apexFile->GetImageSize());
+ EXPECT_EQ(zip_image_offset, apex_file->GetImageOffset());
+ EXPECT_EQ(zip_image_size, apex_file->GetImageSize());
}
TEST(ApexFileTest, GetOffsetMissingFile) {
- const std::string filePath = testDataDir + "missing.apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_FALSE(apexFile.ok());
- ASSERT_THAT(apexFile.error().message(),
+ const std::string file_path = kTestDataDir + "missing.apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_FALSE(apex_file.ok());
+ ASSERT_THAT(apex_file.error().message(),
testing::HasSubstr("Failed to open package"));
}
TEST_P(ApexFileTest, GetApexManifest) {
- const std::string filePath = testDataDir + GetParam().prefix + ".apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_RESULT_OK(apexFile);
- EXPECT_EQ("com.android.apex.test_package", apexFile->GetManifest().name());
- EXPECT_EQ(1u, apexFile->GetManifest().version());
+ const std::string file_path = kTestDataDir + GetParam().prefix + ".apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_RESULT_OK(apex_file);
+ EXPECT_EQ("com.android.apex.test_package", apex_file->GetManifest().name());
+ EXPECT_EQ(1u, apex_file->GetManifest().version());
}
TEST_P(ApexFileTest, VerifyApexVerity) {
- const std::string filePath = testDataDir + GetParam().prefix + ".apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_RESULT_OK(apexFile);
+ const std::string file_path = kTestDataDir + GetParam().prefix + ".apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_RESULT_OK(apex_file);
- auto verity_or = apexFile->VerifyApexVerity(apexFile->GetBundledPublicKey());
+ auto verity_or =
+ apex_file->VerifyApexVerity(apex_file->GetBundledPublicKey());
ASSERT_RESULT_OK(verity_or);
const ApexVerityData& data = *verity_or;
@@ -105,60 +107,60 @@
"50ca7ec8071f49dfa47a243c"),
data.salt);
- const std::string digestPath =
- testDataDir + GetParam().prefix + "_digest.txt";
- std::string rootDigest;
- ASSERT_TRUE(android::base::ReadFileToString(digestPath, &rootDigest))
- << "Failed to read " << digestPath;
- rootDigest = android::base::Trim(rootDigest);
+ const std::string digest_path =
+ kTestDataDir + GetParam().prefix + "_digest.txt";
+ std::string root_digest;
+ ASSERT_TRUE(android::base::ReadFileToString(digest_path, &root_digest))
+ << "Failed to read " << digest_path;
+ root_digest = android::base::Trim(root_digest);
- EXPECT_EQ(std::string(rootDigest), data.root_digest);
+ EXPECT_EQ(std::string(root_digest), data.root_digest);
}
TEST_P(ApexFileTest, VerifyApexVerityWrongKey) {
- const std::string filePath = testDataDir + GetParam().prefix + ".apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_RESULT_OK(apexFile);
+ const std::string file_path = kTestDataDir + GetParam().prefix + ".apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_RESULT_OK(apex_file);
- auto verity_or = apexFile->VerifyApexVerity("wrong-key");
+ auto verity_or = apex_file->VerifyApexVerity("wrong-key");
ASSERT_FALSE(verity_or.ok());
}
TEST_P(ApexFileTest, GetBundledPublicKey) {
- const std::string filePath = testDataDir + GetParam().prefix + ".apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_RESULT_OK(apexFile);
+ const std::string file_path = kTestDataDir + GetParam().prefix + ".apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_RESULT_OK(apex_file);
- const std::string keyPath =
- testDataDir + "apexd_testdata/com.android.apex.test_package.avbpubkey";
- std::string keyContent;
- ASSERT_TRUE(android::base::ReadFileToString(keyPath, &keyContent))
- << "Failed to read " << keyPath;
+ const std::string key_path =
+ kTestDataDir + "apexd_testdata/com.android.apex.test_package.avbpubkey";
+ std::string key_content;
+ ASSERT_TRUE(android::base::ReadFileToString(key_path, &key_content))
+ << "Failed to read " << key_path;
- EXPECT_EQ(keyContent, apexFile->GetBundledPublicKey());
+ EXPECT_EQ(key_content, apex_file->GetBundledPublicKey());
}
TEST(ApexFileTest, CorrutedApexB146895998) {
- const std::string apex_path = testDataDir + "corrupted_b146895998.apex";
+ const std::string apex_path = kTestDataDir + "corrupted_b146895998.apex";
Result<ApexFile> apex = ApexFile::Open(apex_path);
ASSERT_RESULT_OK(apex);
- ASSERT_FALSE(apex->VerifyApexVerity("ignored"));
+ ASSERT_FALSE(apex->VerifyApexVerity("ignored").ok());
}
TEST_P(ApexFileTest, RetrieveFsType) {
- const std::string filePath = testDataDir + GetParam().prefix + ".apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_TRUE(apexFile.ok());
+ const std::string file_path = kTestDataDir + GetParam().prefix + ".apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_TRUE(apex_file.ok());
- EXPECT_EQ(std::string(GetParam().type), apexFile->GetFsType());
+ EXPECT_EQ(std::string(GetParam().type), apex_file->GetFsType());
}
TEST(ApexFileTest, OpenInvalidFilesystem) {
- const std::string filePath =
- testDataDir + "apex.apexd_test_corrupt_superblock_apex.apex";
- Result<ApexFile> apexFile = ApexFile::Open(filePath);
- ASSERT_FALSE(apexFile.ok());
- ASSERT_THAT(apexFile.error().message(),
+ const std::string file_path =
+ kTestDataDir + "apex.apexd_test_corrupt_superblock_apex.apex";
+ Result<ApexFile> apex_file = ApexFile::Open(file_path);
+ ASSERT_FALSE(apex_file.ok());
+ ASSERT_THAT(apex_file.error().message(),
testing::HasSubstr("Failed to retrieve filesystem type"));
}
diff --git a/apexd/apex_manifest.cpp b/apexd/apex_manifest.cpp
index 1994633..7bd5913 100644
--- a/apexd/apex_manifest.cpp
+++ b/apexd/apex_manifest.cpp
@@ -46,8 +46,8 @@
return apex_manifest;
}
-std::string GetPackageId(const ApexManifest& apexManifest) {
- return apexManifest.name() + "@" + std::to_string(apexManifest.version());
+std::string GetPackageId(const ApexManifest& apex_manifest) {
+ return apex_manifest.name() + "@" + std::to_string(apex_manifest.version());
}
Result<ApexManifest> ReadManifest(const std::string& path) {
diff --git a/apexd/apex_preinstalled_data.cpp b/apexd/apex_preinstalled_data.cpp
index a7b9f49..4ca8373 100644
--- a/apexd/apex_preinstalled_data.cpp
+++ b/apexd/apex_preinstalled_data.cpp
@@ -21,6 +21,7 @@
#include <unordered_map>
#include <android-base/file.h>
+#include <android-base/properties.h>
#include <android-base/result.h>
#include <android-base/strings.h>
@@ -29,6 +30,7 @@
#include "apexd_utils.h"
using android::base::Error;
+using android::base::GetProperty;
using android::base::Result;
namespace android {
@@ -60,10 +62,21 @@
auto it = data_.find(name);
if (it == data_.end()) {
data_[name] = apex_data;
+ } else if (it->second.path != apex_data.path) {
+ // Currently, on some -eng builds there are two art apexes on /system
+ // partition. While this issue is not fixed, exempt art apex from the
+ // duplicate check on -eng builds.
+ // TODO(b/176497601): remove this exemption once issue with duplicate art
+ // apex is resolved.
+ std::string build_type = GetProperty("ro.build.type", "");
+ auto level = build_type == "eng" && name == "com.android.art"
+ ? base::ERROR
+ : base::FATAL;
+ LOG(level) << "Found two apex packages " << it->second.path << " and "
+ << apex_data.path << " with the same module name " << name;
} else if (it->second.public_key != apex_data.public_key) {
- return Error() << "Key for package " << apex_data.path << " ( " << name
- << ") does not match with previously scanned key from "
- << it->second.path;
+ LOG(FATAL) << "Public key of apex package " << it->second.path << " ("
+ << name << ") has unexpectedly changed";
}
}
return {};
diff --git a/apexd/apex_preinstalled_data_test.cpp b/apexd/apex_preinstalled_data_test.cpp
index 8efe68a..a961ed2 100644
--- a/apexd/apex_preinstalled_data_test.cpp
+++ b/apexd/apex_preinstalled_data_test.cpp
@@ -41,7 +41,6 @@
using android::apex::testing::IsOk;
using android::base::GetExecutableDirectory;
using android::base::StringPrintf;
-using ::testing::HasSubstr;
static std::string GetTestDataDir() { return GetExecutableDirectory(); }
static std::string GetTestFile(const std::string& name) {
@@ -79,6 +78,12 @@
test_fn("apex.apexd_test.apex");
test_fn("apex.apexd_test_different_app.apex");
+
+ // Check that second call will succeed as well.
+ ASSERT_TRUE(IsOk(instance.Initialize({td.path})));
+
+ test_fn("apex.apexd_test.apex");
+ test_fn("apex.apexd_test_different_app.apex");
}
TEST(ApexPreinstalledDataTest, InitializeFailureCorruptApex) {
@@ -92,18 +97,52 @@
ASSERT_FALSE(IsOk(instance.Initialize({td.path})));
}
-TEST(ApexPreinstalledData, InitializeFailureSameNameDifferentKeys) {
+TEST(ApexPreinstalledData, InitializeSameNameDifferentPathAborts) {
// Prepare test data.
TemporaryDir td;
fs::copy(GetTestFile("apex.apexd_test.apex"), td.path);
- fs::copy(GetTestFile("apex.apexd_test_different_key.apex"), td.path);
+ fs::copy(GetTestFile("apex.apexd_test.apex"),
+ StringPrintf("%s/other.apex", td.path));
+
+ ASSERT_DEATH(
+ {
+ ApexPreinstalledData instance;
+ instance.Initialize({td.path});
+ },
+ "");
+}
+
+TEST(ApexPreinstalledData, InitializePublicKeyUnexpectdlyChangedAborts) {
+ // Prepare test data.
+ TemporaryDir td;
+ fs::copy(GetTestFile("apex.apexd_test.apex"), td.path);
ApexPreinstalledData instance;
- auto result = instance.Initialize({td.path});
+ ASSERT_TRUE(IsOk(instance.Initialize({td.path})));
- ASSERT_FALSE(IsOk(result));
- ASSERT_THAT(result.error().message(),
- HasSubstr("does not match with previously scanned key"));
+ // Check that apex was loaded.
+ auto path = instance.GetPreinstalledPath("com.android.apex.test_package");
+ ASSERT_TRUE(IsOk(path));
+ ASSERT_EQ(StringPrintf("%s/apex.apexd_test.apex", td.path), *path);
+
+ auto public_key = instance.GetPublicKey("com.android.apex.test_package");
+ ASSERT_TRUE(IsOk(public_key));
+
+ // Substitute it with another apex with the same name, but different public
+ // key.
+ fs::copy(GetTestFile("apex.apexd_test_different_key.apex"), *path,
+ fs::copy_options::overwrite_existing);
+
+ {
+ auto apex = ApexFile::Open(*path);
+ ASSERT_TRUE(IsOk(apex));
+ // Check module name hasn't changed.
+ ASSERT_EQ("com.android.apex.test_package", apex->GetManifest().name());
+ // Check public key has changed.
+ ASSERT_NE(*public_key, apex->GetBundledPublicKey());
+ }
+
+ ASSERT_DEATH({ instance.Initialize({td.path}); }, "");
}
TEST(ApexPreinstalledData, IsPreInstalledApex) {
diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp
index c2439af..98a0d07 100644
--- a/apexd/apexd.cpp
+++ b/apexd/apexd.cpp
@@ -137,14 +137,14 @@
static constexpr const int kNumRetriesWhenCheckpointingEnabled = 1;
-bool isBootstrapApex(const ApexFile& apex) {
+bool IsBootstrapApex(const ApexFile& apex) {
return std::find(kBootstrapApexes.begin(), kBootstrapApexes.end(),
apex.GetManifest().name()) != kBootstrapApexes.end();
}
// Pre-allocate loop devices so that we don't have to wait for them
// later when actually activating APEXes.
-Result<void> preAllocateLoopDevices() {
+Result<void> PreAllocateLoopDevices() {
auto scan = FindApexes(kApexPackageBuiltinDirs);
if (!scan.ok()) {
return scan.error();
@@ -158,22 +158,22 @@
}
size++;
// bootstrap Apexes may be activated on separate namespaces.
- if (isBootstrapApex(*apexFile)) {
+ if (IsBootstrapApex(*apexFile)) {
size++;
}
}
- // note: do not call preAllocateLoopDevices() if size == 0.
+ // note: do not call PreAllocateLoopDevices() if size == 0.
// For devices (e.g. ARC) which doesn't support loop-control
- // preAllocateLoopDevices() can cause problem when it tries
+ // PreAllocateLoopDevices() can cause problem when it tries
// to access /dev/loop-control.
if (size == 0) {
return {};
}
- return loop::preAllocateLoopDevices(size);
+ return loop::PreAllocateLoopDevices(size);
}
-std::unique_ptr<DmTable> createVerityTable(const ApexVerityData& verity_data,
+std::unique_ptr<DmTable> CreateVerityTable(const ApexVerityData& verity_data,
const std::string& block_device,
const std::string& hash_device,
bool restart_on_corruption) {
@@ -257,7 +257,7 @@
bool cleared_;
};
-Result<DmVerityDevice> createVerityDevice(const std::string& name,
+Result<DmVerityDevice> CreateVerityDevice(const std::string& name,
const DmTable& table) {
DeviceMapper& dm = DeviceMapper::Instance();
@@ -315,7 +315,7 @@
}
// Reads the entire device to verify the image is authenticatic
-Result<void> readVerityDevice(const std::string& verity_device,
+Result<void> ReadVerityDevice(const std::string& verity_device,
uint64_t device_size) {
static constexpr int kBlockSize = 4096;
static constexpr size_t kBufSize = 1024 * kBlockSize;
@@ -359,12 +359,12 @@
}
Result<MountedApexData> MountPackageImpl(const ApexFile& apex,
- const std::string& mountPoint,
+ const std::string& mount_point,
const std::string& device_name,
const std::string& hashtree_file,
- bool verifyImage,
- bool tempMount = false) {
- LOG(VERBOSE) << "Creating mount point: " << mountPoint;
+ bool verify_image,
+ bool temp_mount = false) {
+ LOG(VERBOSE) << "Creating mount point: " << mount_point;
// Note: the mount point could exist in case when the APEX was activated
// during the bootstrap phase (e.g., the runtime or tzdata APEX).
// Although we have separate mount namespaces to separate the early activated
@@ -373,31 +373,31 @@
// mounted at / which is (and has to be) a shared mount. Therefore, if apexd
// finds an empty directory under /apex, it's not a problem and apexd can use
// it.
- auto exists = PathExists(mountPoint);
+ auto exists = PathExists(mount_point);
if (!exists.ok()) {
return exists.error();
}
- if (!*exists && mkdir(mountPoint.c_str(), kMkdirMode) != 0) {
- return ErrnoError() << "Could not create mount point " << mountPoint;
+ if (!*exists && mkdir(mount_point.c_str(), kMkdirMode) != 0) {
+ return ErrnoError() << "Could not create mount point " << mount_point;
}
- auto deleter = [&mountPoint]() {
- if (rmdir(mountPoint.c_str()) != 0) {
- PLOG(WARNING) << "Could not rmdir " << mountPoint;
+ auto deleter = [&mount_point]() {
+ if (rmdir(mount_point.c_str()) != 0) {
+ PLOG(WARNING) << "Could not rmdir " << mount_point;
}
};
auto scope_guard = android::base::make_scope_guard(deleter);
- if (!IsEmptyDirectory(mountPoint)) {
- return ErrnoError() << mountPoint << " is not empty";
+ if (!IsEmptyDirectory(mount_point)) {
+ return ErrnoError() << mount_point << " is not empty";
}
const std::string& full_path = apex.GetPath();
- loop::LoopbackDeviceUniqueFd loopbackDevice;
+ loop::LoopbackDeviceUniqueFd loopback_device;
for (size_t attempts = 1;; ++attempts) {
- Result<loop::LoopbackDeviceUniqueFd> ret = loop::createLoopDevice(
+ Result<loop::LoopbackDeviceUniqueFd> ret = loop::CreateLoopDevice(
full_path, apex.GetImageOffset(), apex.GetImageSize());
if (ret.ok()) {
- loopbackDevice = std::move(*ret);
+ loopback_device = std::move(*ret);
break;
}
if (attempts >= kLoopDeviceSetupAttempts) {
@@ -405,7 +405,7 @@
<< ret.error();
}
}
- LOG(VERBOSE) << "Loopback device created: " << loopbackDevice.name;
+ LOG(VERBOSE) << "Loopback device created: " << loopback_device.name;
auto& instance = ApexPreinstalledData::GetInstance();
@@ -414,32 +414,32 @@
return public_key.error();
}
- auto verityData = apex.VerifyApexVerity(*public_key);
- if (!verityData.ok()) {
+ auto verity_data = apex.VerifyApexVerity(*public_key);
+ if (!verity_data.ok()) {
return Error() << "Failed to verify Apex Verity data for " << full_path
- << ": " << verityData.error();
+ << ": " << verity_data.error();
}
- std::string blockDevice = loopbackDevice.name;
- MountedApexData apex_data(loopbackDevice.name, apex.GetPath(), mountPoint,
+ std::string block_device = loopback_device.name;
+ MountedApexData apex_data(loopback_device.name, apex.GetPath(), mount_point,
/* device_name = */ "",
/* hashtree_loop_name = */ "",
- /* is_temp_mount */ tempMount);
+ /* is_temp_mount */ temp_mount);
// for APEXes in immutable partitions, we don't need to mount them on
// dm-verity because they are already in the dm-verity protected partition;
// system. However, note that we don't skip verification to ensure that APEXes
// are correctly signed.
- const bool mountOnVerity = !instance.IsPreInstalledApex(apex);
- DmVerityDevice verityDev;
+ const bool mount_on_verity = !instance.IsPreInstalledApex(apex);
+ DmVerityDevice verity_dev;
loop::LoopbackDeviceUniqueFd loop_for_hash;
- if (mountOnVerity) {
- std::string hash_device = loopbackDevice.name;
- if (verityData->desc->tree_size == 0) {
- if (auto st = PrepareHashTree(apex, *verityData, hashtree_file);
+ if (mount_on_verity) {
+ std::string hash_device = loopback_device.name;
+ if (verity_data->desc->tree_size == 0) {
+ if (auto st = PrepareHashTree(apex, *verity_data, hashtree_file);
!st.ok()) {
return st.error();
}
- auto create_loop_status = loop::createLoopDevice(hashtree_file, 0, 0);
+ auto create_loop_status = loop::CreateLoopDevice(hashtree_file, 0, 0);
if (!create_loop_status.ok()) {
return create_loop_status.error();
}
@@ -447,54 +447,54 @@
hash_device = loop_for_hash.name;
apex_data.hashtree_loop_name = hash_device;
}
- auto verityTable =
- createVerityTable(*verityData, loopbackDevice.name, hash_device,
- /* restart_on_corruption = */ !verifyImage);
- Result<DmVerityDevice> verityDevRes =
- createVerityDevice(device_name, *verityTable);
- if (!verityDevRes.ok()) {
+ auto verity_table =
+ CreateVerityTable(*verity_data, loopback_device.name, hash_device,
+ /* restart_on_corruption = */ !verify_image);
+ Result<DmVerityDevice> verity_dev_res =
+ CreateVerityDevice(device_name, *verity_table);
+ if (!verity_dev_res.ok()) {
return Error() << "Failed to create Apex Verity device " << full_path
- << ": " << verityDevRes.error();
+ << ": " << verity_dev_res.error();
}
- verityDev = std::move(*verityDevRes);
+ verity_dev = std::move(*verity_dev_res);
apex_data.device_name = device_name;
- blockDevice = verityDev.GetDevPath();
+ block_device = verity_dev.GetDevPath();
- Result<void> readAheadStatus =
- loop::configureReadAhead(verityDev.GetDevPath());
- if (!readAheadStatus.ok()) {
- return readAheadStatus.error();
+ Result<void> read_ahead_status =
+ loop::ConfigureReadAhead(verity_dev.GetDevPath());
+ if (!read_ahead_status.ok()) {
+ return read_ahead_status.error();
}
}
// TODO(b/158467418): consider moving this inside RunVerifyFnInsideTempMount.
- if (mountOnVerity && verifyImage) {
- Result<void> verityStatus =
- readVerityDevice(blockDevice, (*verityData).desc->image_size);
- if (!verityStatus.ok()) {
- return verityStatus.error();
+ if (mount_on_verity && verify_image) {
+ Result<void> verity_status =
+ ReadVerityDevice(block_device, (*verity_data).desc->image_size);
+ if (!verity_status.ok()) {
+ return verity_status.error();
}
}
- uint32_t mountFlags = MS_NOATIME | MS_NODEV | MS_DIRSYNC | MS_RDONLY;
+ uint32_t mount_flags = MS_NOATIME | MS_NODEV | MS_DIRSYNC | MS_RDONLY;
if (apex.GetManifest().nocode()) {
- mountFlags |= MS_NOEXEC;
+ mount_flags |= MS_NOEXEC;
}
- if (mount(blockDevice.c_str(), mountPoint.c_str(), apex.GetFsType().c_str(),
- mountFlags, nullptr) == 0) {
+ if (mount(block_device.c_str(), mount_point.c_str(), apex.GetFsType().c_str(),
+ mount_flags, nullptr) == 0) {
LOG(INFO) << "Successfully mounted package " << full_path << " on "
- << mountPoint;
- auto status = VerifyMountedImage(apex, mountPoint);
+ << mount_point;
+ auto status = VerifyMountedImage(apex, mount_point);
if (!status.ok()) {
- if (umount2(mountPoint.c_str(), UMOUNT_NOFOLLOW) != 0) {
- PLOG(ERROR) << "Failed to umount " << mountPoint;
+ if (umount2(mount_point.c_str(), UMOUNT_NOFOLLOW) != 0) {
+ PLOG(ERROR) << "Failed to umount " << mount_point;
}
return Error() << "Failed to verify " << full_path << ": "
<< status.error();
}
// Time to accept the temporaries as good.
- verityDev.Release();
- loopbackDevice.CloseGood();
+ verity_dev.Release();
+ loopback_device.CloseGood();
loop_for_hash.CloseGood();
scope_guard.Disable(); // Accept the mount.
@@ -524,7 +524,7 @@
}
auto ret =
MountPackageImpl(apex, mount_point, temp_device_name, hashtree_file,
- /* verifyImage = */ true, /* tempMount = */ true);
+ /* verify_image = */ true, /* temp_mount = */ true);
if (!ret.ok()) {
LOG(DEBUG) << "Cleaning up " << hashtree_file;
if (TEMP_FAILURE_RETRY(unlink(hashtree_file.c_str())) != 0) {
@@ -635,7 +635,7 @@
std::string mount_point =
apexd_private::GetPackageTempMountPoint(apex.GetManifest());
Result<MountedApexData> mount_data =
- apexd_private::getTempMountedApexData(apex.GetManifest().name());
+ apexd_private::GetTempMountedApexData(apex.GetManifest().name());
if (!mount_data.ok()) {
mount_data = VerifyAndTempMountPackage(apex, mount_point);
if (!mount_data.ok()) {
@@ -723,7 +723,7 @@
return {};
}
-// A version of apex verification that happens on submitStagedSession.
+// A version of apex verification that happens on SubmitStagedSession.
// This function contains checks that might be expensive to perform, e.g. temp
// mounting a package and reading entire dm-verity device, and shouldn't be run
// during boot.
@@ -740,14 +740,14 @@
}
template <typename VerifyApexFn>
-Result<std::vector<ApexFile>> verifyPackages(
+Result<std::vector<ApexFile>> VerifyPackages(
const std::vector<std::string>& paths, const VerifyApexFn& verify_apex_fn) {
Result<std::vector<ApexFile>> apex_files = OpenApexFiles(paths);
if (!apex_files.ok()) {
return apex_files.error();
}
- LOG(DEBUG) << "verifyPackages() for " << Join(paths, ',');
+ LOG(DEBUG) << "VerifyPackages() for " << Join(paths, ',');
for (const ApexFile& apex_file : *apex_files) {
Result<void> result = verify_apex_fn(apex_file);
@@ -758,12 +758,12 @@
return std::move(*apex_files);
}
-Result<ApexFile> verifySessionDir(const int session_id) {
- std::string sessionDirPath = std::string(kStagedSessionsDir) + "/session_" +
- std::to_string(session_id);
- LOG(INFO) << "Scanning " << sessionDirPath
+Result<ApexFile> VerifySessionDir(const int session_id) {
+ std::string session_dir_path = std::string(kStagedSessionsDir) + "/session_" +
+ std::to_string(session_id);
+ LOG(INFO) << "Scanning " << session_dir_path
<< " looking for packages to be validated";
- Result<std::vector<std::string>> scan = FindApexFilesByName(sessionDirPath);
+ Result<std::vector<std::string>> scan = FindApexFilesByName(session_dir_path);
if (!scan.ok()) {
LOG(WARNING) << scan.error();
return scan.error();
@@ -774,7 +774,7 @@
"More than one APEX package found in the same session directory.");
}
- auto verified = verifyPackages(*scan, VerifyPackageInstall);
+ auto verified = VerifyPackages(*scan, VerifyPackageInstall);
if (!verified.ok()) {
return verified.error();
}
@@ -798,7 +798,7 @@
LOG(DEBUG) << "Initializing backup of " << kActiveApexPackagesDataDir;
// Previous restore might've delete backups folder.
- auto create_status = createDirIfNeeded(kApexBackupDir, 0700);
+ auto create_status = CreateDirIfNeeded(kApexBackupDir, 0700);
if (!create_status.ok()) {
return Error() << "Backup failed : " << create_status.error();
}
@@ -935,11 +935,12 @@
} // namespace
-Result<void> MountPackage(const ApexFile& apex, const std::string& mountPoint) {
+Result<void> MountPackage(const ApexFile& apex,
+ const std::string& mount_point) {
auto ret =
- MountPackageImpl(apex, mountPoint, GetPackageId(apex.GetManifest()),
+ MountPackageImpl(apex, mount_point, GetPackageId(apex.GetManifest()),
GetHashTreeFileName(apex, /* is_new = */ false),
- /* verifyImage = */ false);
+ /* verify_image = */ false);
if (!ret.ok()) {
return ret.error();
}
@@ -958,7 +959,7 @@
// If multiple temp mounts exist, ensure that all are unmounted.
while (!finished_unmounting) {
Result<MountedApexData> data =
- apexd_private::getTempMountedApexData(manifest.name());
+ apexd_private::GetTempMountedApexData(manifest.name());
if (!data.ok()) {
finished_unmounting = true;
} else {
@@ -969,7 +970,7 @@
return {};
}
-Result<MountedApexData> getTempMountedApexData(const std::string& package) {
+Result<MountedApexData> GetTempMountedApexData(const std::string& package) {
bool found = false;
Result<MountedApexData> mount_data;
gMountedApexes.ForallMountedApexes(
@@ -1013,24 +1014,24 @@
} // namespace apexd_private
-Result<void> resumeRevertIfNeeded() {
+Result<void> ResumeRevertIfNeeded() {
auto sessions =
ApexSession::GetSessionsInState(SessionState::REVERT_IN_PROGRESS);
if (sessions.empty()) {
return {};
}
- return revertActiveSessions("");
+ return RevertActiveSessions("");
}
-Result<void> activateSharedLibsPackage(const std::string& mountPoint) {
- for (const auto& libPath : {"lib", "lib64"}) {
- std::string apexLibPath = mountPoint + "/" + libPath;
- auto lib_dir = PathExists(apexLibPath);
+Result<void> ActivateSharedLibsPackage(const std::string& mount_point) {
+ for (const auto& lib_path : {"lib", "lib64"}) {
+ std::string apex_lib_path = mount_point + "/" + lib_path;
+ auto lib_dir = PathExists(apex_lib_path);
if (!lib_dir.ok() || !*lib_dir) {
continue;
}
- auto iter = std::filesystem::directory_iterator(apexLibPath);
+ auto iter = std::filesystem::directory_iterator(apex_lib_path);
std::error_code ec;
while (iter != std::filesystem::end(iter)) {
@@ -1038,7 +1039,7 @@
if (!lib_entry.is_directory()) {
iter = iter.increment(ec);
if (ec) {
- return Error() << "Failed to scan " << apexLibPath << " : "
+ return Error() << "Failed to scan " << apex_lib_path << " : "
<< ec.message();
}
continue;
@@ -1046,8 +1047,8 @@
const auto library_name = lib_entry.path().filename();
const std::string library_symlink_dir =
- StringPrintf("%s/%s/%s/%s", kApexRoot, kApexSharedLibsSubDir, libPath,
- library_name.c_str());
+ StringPrintf("%s/%s/%s/%s", kApexRoot, kApexSharedLibsSubDir,
+ lib_path, library_name.c_str());
auto symlink_dir = PathExists(library_symlink_dir);
if (!symlink_dir.ok() || !*symlink_dir) {
@@ -1069,8 +1070,28 @@
auto hash_dir = PathExists(library_symlink_hash);
if (hash_dir.ok() && *hash_dir) {
- // TODO(b/161542925) : Handle symlink from different sharedlibs APEX
- // with same hash value
+ // Compare file size for two library files with same name and hash
+ // value
+ auto existing_file_path =
+ library_symlink_hash + "/" + library_name.string();
+ auto existing_file_size = GetFileSize(existing_file_path);
+ if (!existing_file_size.ok()) {
+ return existing_file_size.error();
+ }
+
+ auto new_file_path =
+ lib_items.path().string() + "/" + library_name.string();
+ auto new_file_size = GetFileSize(new_file_path);
+ if (!new_file_size.ok()) {
+ return new_file_size.error();
+ }
+
+ if (*existing_file_size != *new_file_size) {
+ return Error() << "There are two libraries with same hash and "
+ "different file size : "
+ << existing_file_path << " and " << new_file_path;
+ }
+
inner_iter = inner_iter.increment(ec);
if (ec) {
return Error() << "Failed to scan " << lib_entry.path().string()
@@ -1094,7 +1115,7 @@
iter = iter.increment(ec);
if (ec) {
- return Error() << "Failed to scan " << apexLibPath << " : "
+ return Error() << "Failed to scan " << apex_lib_path << " : "
<< ec.message();
}
}
@@ -1103,14 +1124,14 @@
return {};
}
-bool isValidPackageName(const std::string& package_name) {
+bool IsValidPackageName(const std::string& package_name) {
return kBannedApexName.count(package_name) == 0;
}
-Result<void> activatePackageImpl(const ApexFile& apex_file) {
+Result<void> ActivatePackageImpl(const ApexFile& apex_file) {
const ApexManifest& manifest = apex_file.GetManifest();
- if (!isValidPackageName(manifest.name())) {
+ if (!IsValidPackageName(manifest.name())) {
return Errorf("Package name {} is not allowed.", manifest.name());
}
@@ -1124,16 +1145,16 @@
bool version_found_active = false;
gMountedApexes.ForallMountedApexes(
manifest.name(), [&](const MountedApexData& data, bool latest) {
- Result<ApexFile> otherApex = ApexFile::Open(data.full_path);
- if (!otherApex.ok()) {
+ Result<ApexFile> other_apex = ApexFile::Open(data.full_path);
+ if (!other_apex.ok()) {
return;
}
- if (static_cast<uint64_t>(otherApex->GetManifest().version()) ==
+ if (static_cast<uint64_t>(other_apex->GetManifest().version()) ==
new_version) {
version_found_mounted = true;
version_found_active = latest;
}
- if (static_cast<uint64_t>(otherApex->GetManifest().version()) >
+ if (static_cast<uint64_t>(other_apex->GetManifest().version()) >
new_version) {
is_newest_version = false;
}
@@ -1150,12 +1171,13 @@
}
}
- const std::string& mountPoint = apexd_private::GetPackageMountPoint(manifest);
+ const std::string& mount_point =
+ apexd_private::GetPackageMountPoint(manifest);
if (!version_found_mounted) {
- auto mountStatus = MountPackage(apex_file, mountPoint);
- if (!mountStatus.ok()) {
- return mountStatus;
+ auto mount_status = MountPackage(apex_file, mount_point);
+ if (!mount_status.ok()) {
+ return mount_status;
}
}
@@ -1173,7 +1195,7 @@
// package provides shared libraries to other APEXs.
if (is_newest_version) {
const Result<void>& update_st = apexd_private::BindMount(
- apexd_private::GetActiveMountPoint(manifest), mountPoint);
+ apexd_private::GetActiveMountPoint(manifest), mount_point);
mounted_latest = update_st.has_value();
if (!update_st.ok()) {
return Error() << "Failed to update package " << manifest.name()
@@ -1187,9 +1209,10 @@
}
if (manifest.providesharedapexlibs()) {
- const auto& handleSharedLibsApex = activateSharedLibsPackage(mountPoint);
- if (!handleSharedLibsApex.ok()) {
- return handleSharedLibsApex;
+ const auto& handle_shared_libs_apex =
+ ActivateSharedLibsPackage(mount_point);
+ if (!handle_shared_libs_apex.ok()) {
+ return handle_shared_libs_apex;
}
}
@@ -1199,28 +1222,28 @@
return {};
}
-Result<void> activatePackage(const std::string& full_path) {
+Result<void> ActivatePackage(const std::string& full_path) {
LOG(INFO) << "Trying to activate " << full_path;
Result<ApexFile> apex_file = ApexFile::Open(full_path);
if (!apex_file.ok()) {
return apex_file.error();
}
- return activatePackageImpl(*apex_file);
+ return ActivatePackageImpl(*apex_file);
}
-Result<void> deactivatePackage(const std::string& full_path) {
+Result<void> DeactivatePackage(const std::string& full_path) {
LOG(INFO) << "Trying to deactivate " << full_path;
- Result<ApexFile> apexFile = ApexFile::Open(full_path);
- if (!apexFile.ok()) {
- return apexFile.error();
+ Result<ApexFile> apex_file = ApexFile::Open(full_path);
+ if (!apex_file.ok()) {
+ return apex_file.error();
}
- return UnmountPackage(*apexFile, /* allow_latest= */ true);
+ return UnmountPackage(*apex_file, /* allow_latest= */ true);
}
-std::vector<ApexFile> getActivePackages() {
+std::vector<ApexFile> GetActivePackages() {
std::vector<ApexFile> ret;
gMountedApexes.ForallMountedApexes(
[&](const std::string&, const MountedApexData& data, bool latest) {
@@ -1228,97 +1251,99 @@
return;
}
- Result<ApexFile> apexFile = ApexFile::Open(data.full_path);
- if (!apexFile.ok()) {
+ Result<ApexFile> apex_file = ApexFile::Open(data.full_path);
+ if (!apex_file.ok()) {
return;
}
- ret.emplace_back(std::move(*apexFile));
+ ret.emplace_back(std::move(*apex_file));
});
return ret;
}
-Result<void> emitApexInfoList(bool is_bootstrap) {
+Result<void> EmitApexInfoList(bool is_bootstrap) {
// on a non-updatable device, we don't have APEX database to emit
if (!android::sysprop::ApexProperties::updatable().value_or(false)) {
return {};
}
- std::vector<com::android::apex::ApexInfo> apexInfos;
+ std::vector<com::android::apex::ApexInfo> apex_infos;
- auto convertToAutogen = [&apexInfos](const ApexFile& apex, bool isActive) {
+ auto convert_to_autogen = [&apex_infos](const ApexFile& apex,
+ bool is_active) {
auto& instance = ApexPreinstalledData::GetInstance();
- auto preinstalledPath =
+ auto preinstalled_path =
instance.GetPreinstalledPath(apex.GetManifest().name());
- std::optional<std::string> preinstalledModulePath;
- if (preinstalledPath.ok()) {
- preinstalledModulePath = *preinstalledPath;
+ std::optional<std::string> preinstalled_module_path;
+ if (preinstalled_path.ok()) {
+ preinstalled_module_path = *preinstalled_path;
}
- com::android::apex::ApexInfo apexInfo(
- apex.GetManifest().name(), apex.GetPath(), preinstalledModulePath,
+ com::android::apex::ApexInfo apex_info(
+ apex.GetManifest().name(), apex.GetPath(), preinstalled_module_path,
apex.GetManifest().version(), apex.GetManifest().versionname(),
- instance.IsPreInstalledApex(apex), isActive);
- apexInfos.emplace_back(apexInfo);
+ instance.IsPreInstalledApex(apex), is_active);
+ apex_infos.emplace_back(apex_info);
};
// Apexd runs both in "bootstrap" and "default" mount namespace.
// To expose /apex/apex-info-list.xml separately in each mount namespaces,
// we write /apex/.<namespace>-apex-info-list .xml file first and then
// bind mount it to the canonical file (/apex/apex-info-list.xml).
- const std::string fileName =
+ const std::string file_name =
fmt::format("{}/.{}-{}", kApexRoot,
is_bootstrap ? "bootstrap" : "default", kApexInfoList);
unique_fd fd(TEMP_FAILURE_RETRY(
- open(fileName.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644)));
+ open(file_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644)));
if (fd.get() == -1) {
- return ErrnoErrorf("Can't open {}", fileName);
+ return ErrnoErrorf("Can't open {}", file_name);
}
- const auto& active = getActivePackages();
+ const auto& active = GetActivePackages();
for (const auto& apex : active) {
- convertToAutogen(apex, true /* isActive */);
+ convert_to_autogen(apex, true /* is_active */);
}
// we skip for non-activated built-in apexes in bootstrap mode
// in order to avoid boottime increase
if (!is_bootstrap) {
- for (const auto& apex : getFactoryPackages()) {
+ for (const auto& apex : GetFactoryPackages()) {
const auto& same_path = [&apex](const auto& o) {
return o.GetPath() == apex.GetPath();
};
if (std::find_if(active.begin(), active.end(), same_path) ==
active.end()) {
- convertToAutogen(apex, false /* isActive */);
+ convert_to_autogen(apex, false /* is_active */);
}
}
}
std::stringstream xml;
- com::android::apex::ApexInfoList apexInfoList(apexInfos);
- com::android::apex::write(xml, apexInfoList);
+ com::android::apex::ApexInfoList apex_info_list(apex_infos);
+ com::android::apex::write(xml, apex_info_list);
if (!android::base::WriteStringToFd(xml.str(), fd)) {
- return ErrnoErrorf("Can't write to {}", fileName);
+ return ErrnoErrorf("Can't write to {}", file_name);
}
fd.reset();
- const std::string mountPoint = fmt::format("{}/{}", kApexRoot, kApexInfoList);
- if (access(mountPoint.c_str(), F_OK) != 0) {
- close(open(mountPoint.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
+ const std::string mount_point =
+ fmt::format("{}/{}", kApexRoot, kApexInfoList);
+ if (access(mount_point.c_str(), F_OK) != 0) {
+ close(open(mount_point.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
0644));
}
- if (mount(fileName.c_str(), mountPoint.c_str(), nullptr, MS_BIND, nullptr) ==
- -1) {
- return ErrnoErrorf("Can't bind mount {} to {}", fileName, mountPoint);
+ if (mount(file_name.c_str(), mount_point.c_str(), nullptr, MS_BIND,
+ nullptr) == -1) {
+ return ErrnoErrorf("Can't bind mount {} to {}", file_name, mount_point);
}
- return RestoreconPath(fileName);
+ return RestoreconPath(file_name);
}
namespace {
std::unordered_map<std::string, uint64_t> GetActivePackagesMap() {
- std::vector<ApexFile> active_packages = getActivePackages();
+ std::vector<ApexFile> active_packages = GetActivePackages();
std::unordered_map<std::string, uint64_t> ret;
for (const auto& package : active_packages) {
const ApexManifest& manifest = package.GetManifest();
@@ -1329,7 +1354,7 @@
} // namespace
-std::vector<ApexFile> getFactoryPackages() {
+std::vector<ApexFile> GetFactoryPackages() {
std::vector<ApexFile> ret;
for (const auto& dir : kApexPackageBuiltinDirs) {
auto apex_files = FindApexFilesByName(dir);
@@ -1349,8 +1374,8 @@
return ret;
}
-Result<ApexFile> getActivePackage(const std::string& packageName) {
- std::vector<ApexFile> packages = getActivePackages();
+Result<ApexFile> GetActivePackage(const std::string& packageName) {
+ std::vector<ApexFile> packages = GetActivePackages();
for (ApexFile& apex : packages) {
if (apex.GetManifest().name() == packageName) {
return std::move(apex);
@@ -1365,7 +1390,7 @@
*
* Returns without error only if session was successfully aborted.
**/
-Result<void> abortStagedSession(int session_id) {
+Result<void> AbortStagedSession(int session_id) {
auto session = ApexSession::GetSession(session_id);
if (!session.ok()) {
return Error() << "No session found with id " << session_id;
@@ -1426,7 +1451,7 @@
}
}
- if (auto res = activatePackageImpl(apex); !res.ok()) {
+ if (auto res = ActivatePackageImpl(apex); !res.ok()) {
LOG(ERROR) << "Failed to activate " << apex.GetPath() << " : "
<< res.error();
failed_cnt++;
@@ -1449,7 +1474,7 @@
} // namespace
-Result<void> scanPackagesDirAndActivate(const char* apex_package_dir) {
+Result<void> ScanPackagesDirAndActivate(const char* apex_package_dir) {
auto apexes = ScanApexFiles(apex_package_dir);
if (!apexes.ok()) {
return apexes.error();
@@ -1461,14 +1486,14 @@
* Snapshots data from base_dir/apexdata/<apex name> to
* base_dir/apexrollback/<rollback id>/<apex name>.
*/
-Result<void> snapshotDataDirectory(const std::string& base_dir,
+Result<void> SnapshotDataDirectory(const std::string& base_dir,
const int rollback_id,
const std::string& apex_name,
bool pre_restore = false) {
auto rollback_path =
StringPrintf("%s/%s/%d%s", base_dir.c_str(), kApexSnapshotSubDir,
rollback_id, pre_restore ? kPreRestoreSuffix : "");
- const Result<void> result = createDirIfNeeded(rollback_path, 0700);
+ const Result<void> result = CreateDirIfNeeded(rollback_path, 0700);
if (!result.ok()) {
return Error() << "Failed to create snapshot directory for rollback "
<< rollback_id << " : " << result.error();
@@ -1486,7 +1511,7 @@
* to base_dir/apexdata/<apex name>.
* Note the snapshot will be deleted after restoration succeeded.
*/
-Result<void> restoreDataDirectory(const std::string& base_dir,
+Result<void> RestoreDataDirectory(const std::string& base_dir,
const int rollback_id,
const std::string& apex_name,
bool pre_restore = false) {
@@ -1510,12 +1535,12 @@
return {};
}
-void snapshotOrRestoreDeIfNeeded(const std::string& base_dir,
+void SnapshotOrRestoreDeIfNeeded(const std::string& base_dir,
const ApexSession& session) {
if (session.HasRollbackEnabled()) {
for (const auto& apex_name : session.GetApexNames()) {
Result<void> result =
- snapshotDataDirectory(base_dir, session.GetRollbackId(), apex_name);
+ SnapshotDataDirectory(base_dir, session.GetRollbackId(), apex_name);
if (!result.ok()) {
LOG(ERROR) << "Snapshot failed for " << apex_name << ": "
<< result.error();
@@ -1525,11 +1550,11 @@
for (const auto& apex_name : session.GetApexNames()) {
if (!gInFsCheckpointMode) {
// Snapshot before restore so this rollback can be reverted.
- snapshotDataDirectory(base_dir, session.GetRollbackId(), apex_name,
+ SnapshotDataDirectory(base_dir, session.GetRollbackId(), apex_name,
true /* pre_restore */);
}
Result<void> result =
- restoreDataDirectory(base_dir, session.GetRollbackId(), apex_name);
+ RestoreDataDirectory(base_dir, session.GetRollbackId(), apex_name);
if (!result.ok()) {
LOG(ERROR) << "Restore of data failed for " << apex_name << ": "
<< result.error();
@@ -1538,15 +1563,15 @@
}
}
-void snapshotOrRestoreDeSysData() {
+void SnapshotOrRestoreDeSysData() {
auto sessions = ApexSession::GetSessionsInState(SessionState::ACTIVATED);
for (const ApexSession& session : sessions) {
- snapshotOrRestoreDeIfNeeded(kDeSysDataDir, session);
+ SnapshotOrRestoreDeIfNeeded(kDeSysDataDir, session);
}
}
-int snapshotOrRestoreDeUserData() {
+int SnapshotOrRestoreDeUserData() {
auto user_dirs = GetDeUserDirs();
if (!user_dirs.ok()) {
@@ -1558,47 +1583,40 @@
for (const ApexSession& session : sessions) {
for (const auto& user_dir : *user_dirs) {
- snapshotOrRestoreDeIfNeeded(user_dir, session);
+ SnapshotOrRestoreDeIfNeeded(user_dir, session);
}
}
return 0;
}
-Result<ino_t> snapshotCeData(const int user_id, const int rollback_id,
- const std::string& apex_name) {
+Result<void> SnapshotCeData(const int user_id, const int rollback_id,
+ const std::string& apex_name) {
auto base_dir = StringPrintf("%s/%d", kCeDataDir, user_id);
- Result<void> result = snapshotDataDirectory(base_dir, rollback_id, apex_name);
- if (!result.ok()) {
- return result.error();
- }
- auto ce_snapshot_path =
- StringPrintf("%s/%s/%d/%s", base_dir.c_str(), kApexSnapshotSubDir,
- rollback_id, apex_name.c_str());
- return get_path_inode(ce_snapshot_path);
+ return SnapshotDataDirectory(base_dir, rollback_id, apex_name);
}
-Result<void> restoreCeData(const int user_id, const int rollback_id,
+Result<void> RestoreCeData(const int user_id, const int rollback_id,
const std::string& apex_name) {
auto base_dir = StringPrintf("%s/%d", kCeDataDir, user_id);
- return restoreDataDirectory(base_dir, rollback_id, apex_name);
+ return RestoreDataDirectory(base_dir, rollback_id, apex_name);
}
// Migrates sessions directory from /data/apex/sessions to
// /metadata/apex/sessions, if necessary.
-Result<void> migrateSessionsDirIfNeeded() {
+Result<void> MigrateSessionsDirIfNeeded() {
return ApexSession::MigrateToMetadataSessionsDir();
}
-Result<void> destroySnapshots(const std::string& base_dir,
+Result<void> DestroySnapshots(const std::string& base_dir,
const int rollback_id) {
auto path = StringPrintf("%s/%s/%d", base_dir.c_str(), kApexSnapshotSubDir,
rollback_id);
return DeleteDir(path);
}
-Result<void> destroyDeSnapshots(const int rollback_id) {
- destroySnapshots(kDeSysDataDir, rollback_id);
+Result<void> DestroyDeSnapshots(const int rollback_id) {
+ DestroySnapshots(kDeSysDataDir, rollback_id);
auto user_dirs = GetDeUserDirs();
if (!user_dirs.ok()) {
@@ -1606,22 +1624,28 @@
}
for (const auto& user_dir : *user_dirs) {
- destroySnapshots(user_dir, rollback_id);
+ DestroySnapshots(user_dir, rollback_id);
}
return {};
}
+Result<void> DestroyCeSnapshots(const int user_id, const int rollback_id) {
+ auto path = StringPrintf("%s/%d/%s/%d", kCeDataDir, user_id,
+ kApexSnapshotSubDir, rollback_id);
+ return DeleteDir(path);
+}
+
/**
* Deletes all credential-encrypted snapshots for the given user, except for
* those listed in retain_rollback_ids.
*/
-Result<void> destroyCeSnapshotsNotSpecified(
+Result<void> DestroyCeSnapshotsNotSpecified(
int user_id, const std::vector<int>& retain_rollback_ids) {
auto snapshot_root =
StringPrintf("%s/%d/%s", kCeDataDir, user_id, kApexSnapshotSubDir);
auto snapshot_dirs = GetSubdirs(snapshot_root);
- if (!snapshot_dirs) {
+ if (!snapshot_dirs.ok()) {
return Error() << "Error reading snapshot dirs " << snapshot_dirs.error();
}
@@ -1633,7 +1657,7 @@
std::find(retain_rollback_ids.begin(), retain_rollback_ids.end(),
snapshot_id) == retain_rollback_ids.end()) {
Result<void> result = DeleteDir(snapshot_dir);
- if (!result) {
+ if (!result.ok()) {
return Error() << "Destroy CE snapshot failed for " << snapshot_dir
<< " : " << result.error();
}
@@ -1642,14 +1666,14 @@
return {};
}
-void restorePreRestoreSnapshotsIfPresent(const std::string& base_dir,
+void RestorePreRestoreSnapshotsIfPresent(const std::string& base_dir,
const ApexSession& session) {
auto pre_restore_snapshot_path =
StringPrintf("%s/%s/%d%s", base_dir.c_str(), kApexSnapshotSubDir,
session.GetRollbackId(), kPreRestoreSuffix);
if (PathExists(pre_restore_snapshot_path).ok()) {
for (const auto& apex_name : session.GetApexNames()) {
- Result<void> result = restoreDataDirectory(
+ Result<void> result = RestoreDataDirectory(
base_dir, session.GetRollbackId(), apex_name, true /* pre_restore */);
if (!result.ok()) {
LOG(ERROR) << "Restore of pre-restore snapshot failed for " << apex_name
@@ -1665,8 +1689,8 @@
}
}
-void restoreDePreRestoreSnapshotsIfPresent(const ApexSession& session) {
- restorePreRestoreSnapshotsIfPresent(kDeSysDataDir, session);
+void RestoreDePreRestoreSnapshotsIfPresent(const ApexSession& session) {
+ RestorePreRestoreSnapshotsIfPresent(kDeSysDataDir, session);
auto user_dirs = GetDeUserDirs();
if (!user_dirs.ok()) {
@@ -1675,11 +1699,11 @@
}
for (const auto& user_dir : *user_dirs) {
- restorePreRestoreSnapshotsIfPresent(user_dir, session);
+ RestorePreRestoreSnapshotsIfPresent(user_dir, session);
}
}
-void deleteDePreRestoreSnapshots(const std::string& base_dir,
+void DeleteDePreRestoreSnapshots(const std::string& base_dir,
const ApexSession& session) {
auto pre_restore_snapshot_path =
StringPrintf("%s/%s/%d%s", base_dir.c_str(), kApexSnapshotSubDir,
@@ -1690,8 +1714,8 @@
}
}
-void deleteDePreRestoreSnapshots(const ApexSession& session) {
- deleteDePreRestoreSnapshots(kDeSysDataDir, session);
+void DeleteDePreRestoreSnapshots(const ApexSession& session) {
+ DeleteDePreRestoreSnapshots(kDeSysDataDir, session);
auto user_dirs = GetDeUserDirs();
if (!user_dirs.ok()) {
@@ -1700,41 +1724,41 @@
}
for (const auto& user_dir : *user_dirs) {
- deleteDePreRestoreSnapshots(user_dir, session);
+ DeleteDePreRestoreSnapshots(user_dir, session);
}
}
-void onBootCompleted() {
- ApexdLifecycle::getInstance().markBootCompleted();
- bootCompletedCleanup();
+void OnBootCompleted() {
+ ApexdLifecycle::GetInstance().MarkBootCompleted();
+ BootCompletedCleanup();
}
-void scanStagedSessionsDirAndStage() {
+void ScanStagedSessionsDirAndStage() {
LOG(INFO) << "Scanning " << ApexSession::GetSessionsDir()
<< " looking for sessions to be activated.";
- auto sessionsToActivate =
+ auto sessions_to_activate =
ApexSession::GetSessionsInState(SessionState::STAGED);
if (gSupportsFsCheckpoints) {
// A session that is in the ACTIVATED state should still be re-activated if
// fs checkpointing is supported. In this case, a session may be in the
// ACTIVATED state yet the data/apex/active directory may have been
// reverted. The session should be reverted in this scenario.
- auto activatedSessions =
+ auto activated_sessions =
ApexSession::GetSessionsInState(SessionState::ACTIVATED);
- sessionsToActivate.insert(sessionsToActivate.end(),
- activatedSessions.begin(),
- activatedSessions.end());
+ sessions_to_activate.insert(sessions_to_activate.end(),
+ activated_sessions.begin(),
+ activated_sessions.end());
}
- for (auto& session : sessionsToActivate) {
- auto sessionId = session.GetId();
+ for (auto& session : sessions_to_activate) {
+ auto session_id = session.GetId();
auto session_failed_fn = [&]() {
- LOG(WARNING) << "Marking session " << sessionId << " as failed.";
+ LOG(WARNING) << "Marking session " << session_id << " as failed.";
auto st = session.UpdateStateAndCommit(SessionState::ACTIVATION_FAILED);
if (!st.ok()) {
- LOG(WARNING) << "Failed to mark session " << sessionId
+ LOG(WARNING) << "Failed to mark session " << session_id
<< " as failed : " << st.error();
}
};
@@ -1746,52 +1770,52 @@
continue;
}
- std::vector<std::string> dirsToScan;
+ std::vector<std::string> dirs_to_scan;
if (session.GetChildSessionIds().empty()) {
- dirsToScan.push_back(std::string(kStagedSessionsDir) + "/session_" +
- std::to_string(sessionId));
+ dirs_to_scan.push_back(std::string(kStagedSessionsDir) + "/session_" +
+ std::to_string(session_id));
} else {
- for (auto childSessionId : session.GetChildSessionIds()) {
- dirsToScan.push_back(std::string(kStagedSessionsDir) + "/session_" +
- std::to_string(childSessionId));
+ for (auto child_session_id : session.GetChildSessionIds()) {
+ dirs_to_scan.push_back(std::string(kStagedSessionsDir) + "/session_" +
+ std::to_string(child_session_id));
}
}
std::vector<std::string> apexes;
- bool scanSuccessful = true;
- for (const auto& dirToScan : dirsToScan) {
- Result<std::vector<std::string>> scan = FindApexFilesByName(dirToScan);
+ bool scan_successful = true;
+ for (const auto& dir_to_scan : dirs_to_scan) {
+ Result<std::vector<std::string>> scan = FindApexFilesByName(dir_to_scan);
if (!scan.ok()) {
LOG(WARNING) << scan.error();
- scanSuccessful = false;
+ scan_successful = false;
break;
}
if (scan->size() > 1) {
LOG(WARNING) << "More than one APEX package found in the same session "
- << "directory " << dirToScan << ", skipping activation.";
- scanSuccessful = false;
+ << "directory " << dir_to_scan << ", skipping activation.";
+ scan_successful = false;
break;
}
if (scan->empty()) {
- LOG(WARNING) << "No APEX packages found while scanning " << dirToScan
- << " session id: " << sessionId << ".";
- scanSuccessful = false;
+ LOG(WARNING) << "No APEX packages found while scanning " << dir_to_scan
+ << " session id: " << session_id << ".";
+ scan_successful = false;
break;
}
apexes.push_back(std::move((*scan)[0]));
}
- if (!scanSuccessful) {
+ if (!scan_successful) {
continue;
}
// Run postinstall, if necessary.
- Result<void> postinstall_status = postinstallPackages(apexes);
+ Result<void> postinstall_status = PostinstallPackages(apexes);
if (!postinstall_status.ok()) {
LOG(ERROR) << "Postinstall failed for session "
- << std::to_string(sessionId) << ": "
+ << std::to_string(session_id) << ": "
<< postinstall_status.error();
continue;
}
@@ -1806,7 +1830,7 @@
session.AddApexName(apex_file->GetManifest().name());
}
- const Result<void> result = stagePackages(apexes);
+ const Result<void> result = StagePackages(apexes);
if (!result.ok()) {
LOG(ERROR) << "Activation failed for packages " << Join(apexes, ',')
<< ": " << result.error();
@@ -1824,21 +1848,21 @@
}
}
-Result<void> preinstallPackages(const std::vector<std::string>& paths) {
+Result<void> PreinstallPackages(const std::vector<std::string>& paths) {
Result<std::vector<ApexFile>> apex_files = OpenApexFiles(paths);
if (!apex_files.ok()) {
return apex_files.error();
}
- LOG(DEBUG) << "preinstallPackages() for " << Join(paths, ',');
+ LOG(DEBUG) << "PreinstallPackages() for " << Join(paths, ',');
return PreinstallPackages(*apex_files);
}
-Result<void> postinstallPackages(const std::vector<std::string>& paths) {
+Result<void> PostinstallPackages(const std::vector<std::string>& paths) {
Result<std::vector<ApexFile>> apex_files = OpenApexFiles(paths);
if (!apex_files.ok()) {
return apex_files.error();
}
- LOG(DEBUG) << "postinstallPackages() for " << Join(paths, ',');
+ LOG(DEBUG) << "PostinstallPackages() for " << Join(paths, ',');
return PostinstallPackages(*apex_files);
}
@@ -1851,24 +1875,24 @@
} // namespace
-Result<void> stagePackages(const std::vector<std::string>& tmpPaths) {
- if (tmpPaths.empty()) {
+Result<void> StagePackages(const std::vector<std::string>& tmp_paths) {
+ if (tmp_paths.empty()) {
return Errorf("Empty set of inputs");
}
- LOG(DEBUG) << "stagePackages() for " << Join(tmpPaths, ',');
+ LOG(DEBUG) << "StagePackages() for " << Join(tmp_paths, ',');
// Note: this function is temporary. As such the code is not optimized, e.g.,
// it will open ApexFiles multiple times.
// 1) Verify all packages.
- auto verify_status = verifyPackages(tmpPaths, VerifyPackageBoot);
+ auto verify_status = VerifyPackages(tmp_paths, VerifyPackageBoot);
if (!verify_status.ok()) {
return verify_status.error();
}
// Make sure that kActiveApexPackagesDataDir exists.
auto create_dir_status =
- createDirIfNeeded(std::string(kActiveApexPackagesDataDir), 0755);
+ CreateDirIfNeeded(std::string(kActiveApexPackagesDataDir), 0755);
if (!create_dir_status.ok()) {
return create_dir_status.error();
}
@@ -1893,7 +1917,7 @@
auto scope_guard = android::base::make_scope_guard(deleter);
std::unordered_set<std::string> staged_packages;
- for (const std::string& path : tmpPaths) {
+ for (const std::string& path : tmp_paths) {
Result<ApexFile> apex_file = ApexFile::Open(path);
if (!apex_file.ok()) {
return apex_file.error();
@@ -1937,11 +1961,11 @@
return RemovePreviouslyActiveApexFiles(staged_packages, staged_files);
}
-Result<void> unstagePackages(const std::vector<std::string>& paths) {
+Result<void> UnstagePackages(const std::vector<std::string>& paths) {
if (paths.empty()) {
return Errorf("Empty set of inputs");
}
- LOG(DEBUG) << "unstagePackages() for " << Join(paths, ',');
+ LOG(DEBUG) << "UnstagePackages() for " << Join(paths, ',');
for (const std::string& path : paths) {
auto apex = ApexFile::Open(path);
@@ -1971,16 +1995,16 @@
* Also, we need to put staged sessions in /data/apex/sessions in REVERTED state
* so that they do not get activated on next reboot.
*/
-Result<void> revertActiveSessions(const std::string& crashing_native_process) {
+Result<void> RevertActiveSessions(const std::string& crashing_native_process) {
// First check whenever there is anything to revert. If there is none, then
// fail. This prevents apexd from boot looping a device in case a native
// process is crashing and there are no apex updates.
- auto activeSessions = ApexSession::GetActiveSessions();
- if (activeSessions.empty()) {
+ auto active_sessions = ApexSession::GetActiveSessions();
+ if (active_sessions.empty()) {
return Error() << "Revert requested, when there are no active sessions.";
}
- for (auto& session : activeSessions) {
+ for (auto& session : active_sessions) {
if (!crashing_native_process.empty()) {
session.SetCrashingNativeProcess(crashing_native_process);
}
@@ -1993,9 +2017,9 @@
}
if (!gInFsCheckpointMode) {
- auto restoreStatus = RestoreActivePackages();
- if (!restoreStatus.ok()) {
- for (auto& session : activeSessions) {
+ auto restore_status = RestoreActivePackages();
+ if (!restore_status.ok()) {
+ for (auto& session : active_sessions) {
auto st = session.UpdateStateAndCommit(SessionState::REVERT_FAILED);
LOG(DEBUG) << "Marking " << session << " as failed to revert";
if (!st.ok()) {
@@ -2003,17 +2027,17 @@
<< " as failed to revert : " << st.error();
}
}
- return restoreStatus;
+ return restore_status;
}
} else {
LOG(INFO) << "Not restoring active packages in checkpoint mode.";
}
- for (auto& session : activeSessions) {
+ for (auto& session : active_sessions) {
if (!gInFsCheckpointMode && session.IsRollback()) {
// If snapshots have already been restored, undo that by restoring the
// pre-restore snapshot.
- restoreDePreRestoreSnapshotsIfPresent(session);
+ RestoreDePreRestoreSnapshotsIfPresent(session);
}
auto status = session.UpdateStateAndCommit(SessionState::REVERTED);
@@ -2026,9 +2050,9 @@
return {};
}
-Result<void> revertActiveSessionsAndReboot(
+Result<void> RevertActiveSessionsAndReboot(
const std::string& crashing_native_process) {
- auto status = revertActiveSessions(crashing_native_process);
+ auto status = RevertActiveSessions(crashing_native_process);
if (!status.ok()) {
return status;
}
@@ -2044,28 +2068,28 @@
return {};
}
-Result<void> createSharedLibsApexDir() {
+Result<void> CreateSharedLibsApexDir() {
// Creates /apex/sharedlibs/lib{,64} for SharedLibs APEXes.
- std::string sharedLibsSubDir =
+ std::string shared_libs_sub_dir =
StringPrintf("%s/%s", kApexRoot, kApexSharedLibsSubDir);
- auto dir_exists = PathExists(sharedLibsSubDir);
+ auto dir_exists = PathExists(shared_libs_sub_dir);
if (!dir_exists.ok() || !*dir_exists) {
std::error_code error_code;
- std::filesystem::create_directory(sharedLibsSubDir, error_code);
+ std::filesystem::create_directory(shared_libs_sub_dir, error_code);
if (error_code) {
- return Error() << "Failed to create directory " << sharedLibsSubDir
+ return Error() << "Failed to create directory " << shared_libs_sub_dir
<< ": " << error_code.message();
}
}
- for (const auto& libPath : {"lib", "lib64"}) {
- std::string apexLibPath =
- StringPrintf("%s/%s", sharedLibsSubDir.c_str(), libPath);
- auto lib_dir_exists = PathExists(apexLibPath);
+ for (const auto& lib_path : {"lib", "lib64"}) {
+ std::string apex_lib_path =
+ StringPrintf("%s/%s", shared_libs_sub_dir.c_str(), lib_path);
+ auto lib_dir_exists = PathExists(apex_lib_path);
if (!lib_dir_exists.ok() || !*lib_dir_exists) {
std::error_code error_code;
- std::filesystem::create_directory(apexLibPath, error_code);
+ std::filesystem::create_directory(apex_lib_path, error_code);
if (error_code) {
- return Error() << "Failed to create directory " << apexLibPath << ": "
+ return Error() << "Failed to create directory " << apex_lib_path << ": "
<< error_code.message();
}
}
@@ -2074,11 +2098,11 @@
return {};
}
-int onBootstrap() {
- Result<void> preAllocate = preAllocateLoopDevices();
- if (!preAllocate.ok()) {
+int OnBootstrap() {
+ Result<void> pre_allocate = PreAllocateLoopDevices();
+ if (!pre_allocate.ok()) {
LOG(ERROR) << "Failed to pre-allocate loop devices : "
- << preAllocate.error();
+ << pre_allocate.error();
}
ApexPreinstalledData& instance = ApexPreinstalledData::GetInstance();
@@ -2091,7 +2115,7 @@
}
// Create directories for APEX shared libraries.
- auto sharedlibs_apex_dir = createSharedLibsApexDir();
+ auto sharedlibs_apex_dir = CreateSharedLibsApexDir();
if (!sharedlibs_apex_dir.ok()) {
LOG(ERROR) << sharedlibs_apex_dir.error();
return 1;
@@ -2108,7 +2132,7 @@
}
std::copy_if(std::make_move_iterator(scan->begin()),
std::make_move_iterator(scan->end()),
- std::back_inserter(bootstrap_apexes), isBootstrapApex);
+ std::back_inserter(bootstrap_apexes), IsBootstrapApex);
}
// Now activate bootstrap apexes.
@@ -2117,19 +2141,19 @@
return 1;
}
- onAllPackagesActivated(/*is_bootstrap=*/true);
+ OnAllPackagesActivated(/*is_bootstrap=*/true);
LOG(INFO) << "Bootstrapping done";
return 0;
}
-Result<void> remountApexFile(const std::string& path) {
- if (auto ret = deactivatePackage(path); !ret.ok()) {
+Result<void> RemountApexFile(const std::string& path) {
+ if (auto ret = DeactivatePackage(path); !ret.ok()) {
return ret;
}
- return activatePackage(path);
+ return ActivatePackage(path);
}
-void initializeVold(CheckpointInterface* checkpoint_service) {
+void InitializeVold(CheckpointInterface* checkpoint_service) {
if (checkpoint_service != nullptr) {
gVoldService = checkpoint_service;
Result<bool> supports_fs_checkpoints =
@@ -2152,8 +2176,8 @@
}
}
-void initialize(CheckpointInterface* checkpoint_service) {
- initializeVold(checkpoint_service);
+void Initialize(CheckpointInterface* checkpoint_service) {
+ InitializeVold(checkpoint_service);
ApexPreinstalledData& instance = ApexPreinstalledData::GetInstance();
Result<void> status = instance.Initialize(kApexPackageBuiltinDirs);
if (!status.ok()) {
@@ -2164,7 +2188,7 @@
gMountedApexes.PopulateFromMounts();
}
-void onStart() {
+void OnStart() {
LOG(INFO) << "Marking APEXd as starting";
if (!android::base::SetProperty(kApexStatusSysprop, kApexStatusStarting)) {
PLOG(ERROR) << "Failed to set " << kApexStatusSysprop << " to "
@@ -2183,20 +2207,20 @@
LOG(INFO) << "Exceeded number of session retries ("
<< kNumRetriesWhenCheckpointingEnabled
<< "). Starting a revert";
- revertActiveSessions("");
+ RevertActiveSessions("");
}
}
// Create directories for APEX shared libraries.
- auto sharedlibs_apex_dir = createSharedLibsApexDir();
+ auto sharedlibs_apex_dir = CreateSharedLibsApexDir();
if (!sharedlibs_apex_dir.ok()) {
LOG(ERROR) << sharedlibs_apex_dir.error();
}
// Activate APEXes from /data/apex. If one in the directory is newer than the
// system one, the new one will eclipse the old one.
- scanStagedSessionsDirAndStage();
- auto status = resumeRevertIfNeeded();
+ ScanStagedSessionsDirAndStage();
+ auto status = ResumeRevertIfNeeded();
if (!status.ok()) {
LOG(ERROR) << "Failed to resume revert : " << status.error();
}
@@ -2205,7 +2229,7 @@
if (auto scan = ScanApexFiles(kActiveApexPackagesDataDir); !scan.ok()) {
LOG(ERROR) << "Failed to scan packages from " << kActiveApexPackagesDataDir
<< " : " << scan.error();
- if (auto revert = revertActiveSessionsAndReboot(""); !revert.ok()) {
+ if (auto revert = RevertActiveSessionsAndReboot(""); !revert.ok()) {
LOG(ERROR) << "Failed to revert : " << revert.error();
}
} else {
@@ -2221,10 +2245,18 @@
std::back_inserter(data_apex), filter_fn);
}
+ if (data_apex.size() > 0) {
+ Result<void> pre_allocate = loop::PreAllocateLoopDevices(data_apex.size());
+ if (!pre_allocate.ok()) {
+ LOG(ERROR) << "Failed to pre-allocate loop devices : "
+ << pre_allocate.error();
+ }
+ }
+
if (auto ret = ActivateApexPackages(data_apex); !ret.ok()) {
LOG(ERROR) << "Failed to activate packages from "
- << kActiveApexPackagesDataDir << " : " << status.error();
- Result<void> revert_status = revertActiveSessionsAndReboot("");
+ << kActiveApexPackagesDataDir << " : " << ret.error();
+ Result<void> revert_status = RevertActiveSessionsAndReboot("");
if (!revert_status.ok()) {
LOG(ERROR) << "Failed to revert : " << revert_status.error()
<< kActiveApexPackagesDataDir << " : " << ret.error();
@@ -2237,7 +2269,7 @@
if (!scan_status.ok()) {
LOG(ERROR) << "Failed to scan APEX packages from " << dir << " : "
<< scan_status.error();
- if (auto revert = revertActiveSessionsAndReboot(""); !revert.ok()) {
+ if (auto revert = RevertActiveSessionsAndReboot(""); !revert.ok()) {
LOG(ERROR) << "Failed to revert : " << revert.error();
}
}
@@ -2249,11 +2281,11 @@
}
// Now that APEXes are mounted, snapshot or restore DE_sys data.
- snapshotOrRestoreDeSysData();
+ SnapshotOrRestoreDeSysData();
}
-void onAllPackagesActivated(bool is_bootstrap) {
- auto result = emitApexInfoList(is_bootstrap);
+void OnAllPackagesActivated(bool is_bootstrap) {
+ auto result = EmitApexInfoList(is_bootstrap);
if (!result.ok()) {
LOG(ERROR) << "cannot emit apex info list: " << result.error();
}
@@ -2276,7 +2308,7 @@
}
}
-void onAllPackagesReady() {
+void OnAllPackagesReady() {
// Set a system property to let other components know that APEXs are
// correctly mounted and ready to be used. Before using any file from APEXs,
// they can query this system property to ensure that they are okay to
@@ -2289,7 +2321,7 @@
}
}
-Result<std::vector<ApexFile>> submitStagedSession(
+Result<std::vector<ApexFile>> SubmitStagedSession(
const int session_id, const std::vector<int>& child_session_ids,
const bool has_rollback_enabled, const bool is_rollback,
const int rollback_id) {
@@ -2314,7 +2346,7 @@
std::vector<ApexFile> ret;
for (int id_to_scan : ids_to_scan) {
- auto verified = verifySessionDir(id_to_scan);
+ auto verified = VerifySessionDir(id_to_scan);
if (!verified.ok()) {
return verified.error();
}
@@ -2351,7 +2383,7 @@
return ret;
}
-Result<void> markStagedSessionReady(const int session_id) {
+Result<void> MarkStagedSessionReady(const int session_id) {
auto session = ApexSession::GetSession(session_id);
if (!session.ok()) {
return session.error();
@@ -2370,7 +2402,7 @@
<< ". Cannot mark it as ready.";
}
-Result<void> markStagedSessionSuccessful(const int session_id) {
+Result<void> MarkStagedSessionSuccessful(const int session_id) {
auto session = ApexSession::GetSession(session_id);
if (!session.ok()) {
return session.error();
@@ -2386,7 +2418,7 @@
<< " as successful : " << cleanup_status.error();
}
if (session->IsRollback() && !gInFsCheckpointMode) {
- deleteDePreRestoreSnapshots(*session);
+ DeleteDePreRestoreSnapshots(*session);
}
return session->UpdateStateAndCommit(SessionState::SUCCESS);
} else {
@@ -2467,13 +2499,13 @@
} // namespace
-void bootCompletedCleanup() {
+void BootCompletedCleanup() {
UnmountDanglingMounts();
RemoveOrphanedApexes();
ApexSession::DeleteFinalizedSessions();
}
-int unmountAll() {
+int UnmountAll() {
gMountedApexes.PopulateFromMounts();
int ret = 0;
gMountedApexes.ForallMountedApexes([&](const std::string& /*package*/,
@@ -2499,7 +2531,7 @@
return ret;
}
-Result<void> remountPackages() {
+Result<void> RemountPackages() {
std::vector<std::string> apexes;
gMountedApexes.ForallMountedApexes([&apexes](const std::string& /*package*/,
const MountedApexData& data,
@@ -2513,7 +2545,7 @@
for (const std::string& apex : apexes) {
// Since this is only used during development workflow, we are trying to
// remount as many apexes as possible instead of failing fast.
- if (auto ret = remountApexFile(apex); !ret) {
+ if (auto ret = RemountApexFile(apex); !ret.ok()) {
LOG(WARNING) << "Failed to remount " << apex << " : " << ret.error();
failed.emplace_back(apex);
}
diff --git a/apexd/apexd.h b/apexd/apexd.h
index dca3efb..bf44e4b 100644
--- a/apexd/apexd.h
+++ b/apexd/apexd.h
@@ -32,96 +32,99 @@
class CheckpointInterface;
-android::base::Result<void> resumeRevertIfNeeded();
+android::base::Result<void> ResumeRevertIfNeeded();
// Keep it for now to make otapreopt_chroot keep happy.
// TODO(b/137086602): remove this function.
-android::base::Result<void> scanPackagesDirAndActivate(
+android::base::Result<void> ScanPackagesDirAndActivate(
const char* apex_package_dir);
-void scanStagedSessionsDirAndStage();
-android::base::Result<void> preinstallPackages(
+void ScanStagedSessionsDirAndStage();
+android::base::Result<void> PreinstallPackages(
const std::vector<std::string>& paths) WARN_UNUSED;
-android::base::Result<void> postinstallPackages(
+android::base::Result<void> PostinstallPackages(
const std::vector<std::string>& paths) WARN_UNUSED;
-android::base::Result<void> stagePackages(
+android::base::Result<void> StagePackages(
const std::vector<std::string>& tmpPaths) WARN_UNUSED;
-android::base::Result<void> unstagePackages(
+android::base::Result<void> UnstagePackages(
const std::vector<std::string>& paths) WARN_UNUSED;
-android::base::Result<std::vector<ApexFile>> submitStagedSession(
+android::base::Result<std::vector<ApexFile>> SubmitStagedSession(
const int session_id, const std::vector<int>& child_session_ids,
const bool has_rollback_enabled, const bool is_rollback,
const int rollback_id) WARN_UNUSED;
-android::base::Result<void> markStagedSessionReady(const int session_id)
+android::base::Result<void> MarkStagedSessionReady(const int session_id)
WARN_UNUSED;
-android::base::Result<void> markStagedSessionSuccessful(const int session_id)
+android::base::Result<void> MarkStagedSessionSuccessful(const int session_id)
WARN_UNUSED;
-android::base::Result<void> revertActiveSessions(
+android::base::Result<void> RevertActiveSessions(
const std::string& crashing_native_process);
-android::base::Result<void> revertActiveSessionsAndReboot(
+android::base::Result<void> RevertActiveSessionsAndReboot(
const std::string& crashing_native_process);
-android::base::Result<void> activatePackage(const std::string& full_path)
+android::base::Result<void> ActivatePackage(const std::string& full_path)
WARN_UNUSED;
-android::base::Result<void> deactivatePackage(const std::string& full_path)
+android::base::Result<void> DeactivatePackage(const std::string& full_path)
WARN_UNUSED;
-std::vector<ApexFile> getActivePackages();
-android::base::Result<ApexFile> getActivePackage(
+std::vector<ApexFile> GetActivePackages();
+android::base::Result<ApexFile> GetActivePackage(
const std::string& package_name);
-std::vector<ApexFile> getFactoryPackages();
+std::vector<ApexFile> GetFactoryPackages();
-android::base::Result<void> abortStagedSession(const int session_id);
-android::base::Result<void> abortActiveSession();
+android::base::Result<void> AbortStagedSession(const int session_id);
+android::base::Result<void> AbortActiveSession();
-android::base::Result<ino_t> snapshotCeData(const int user_id,
- const int rollback_id,
- const std::string& apex_name);
-android::base::Result<void> restoreCeData(const int user_id,
+android::base::Result<void> SnapshotCeData(const int user_id,
+ const int rollback_id,
+ const std::string& apex_name);
+android::base::Result<void> RestoreCeData(const int user_id,
const int rollback_id,
const std::string& apex_name);
-android::base::Result<void> destroyDeSnapshots(const int rollback_id);
-android::base::Result<void> destroyCeSnapshotsNotSpecified(
+
+android::base::Result<void> DestroyDeSnapshots(const int rollback_id);
+android::base::Result<void> DestroyCeSnapshots(const int user_id,
+ const int rollback_id);
+android::base::Result<void> DestroyCeSnapshotsNotSpecified(
int user_id, const std::vector<int>& retain_rollback_ids);
-int onBootstrap();
+int OnBootstrap();
// Sets the values of gVoldService and gInFsCheckpointMode.
-void initializeVold(CheckpointInterface* checkpoint_service);
+void InitializeVold(CheckpointInterface* checkpoint_service);
// Initializes in-memory state (e.g. pre-installed data, activated apexes).
// Must be called first before calling any other boot sequence related function.
-void initialize(CheckpointInterface* checkpoint_service);
+void Initialize(CheckpointInterface* checkpoint_service);
// Migrates sessions from /data/apex/session to /metadata/session.i
// Must only be called during boot (i.e apexd.status is not "ready" or
// "activated").
-android::base::Result<void> migrateSessionsDirIfNeeded();
+android::base::Result<void> MigrateSessionsDirIfNeeded();
// Apex activation logic. Scans staged apex sessions and activates apexes.
// Must only be called during boot (i.e apexd.status is not "ready" or
// "activated").
-void onStart();
+void OnStart();
// Notifies system that apexes are activated by setting apexd.status property to
// "activated".
// Must only be called during boot (i.e. apexd.status is not "ready" or
// "activated").
-void onAllPackagesActivated(bool is_bootstrap);
+void OnAllPackagesActivated(bool is_bootstrap);
// Notifies system that apexes are ready by setting apexd.status property to
// "ready".
// Must only be called during boot (i.e. apexd.status is not "ready" or
// "activated").
-void onAllPackagesReady();
-void onBootCompleted();
-void bootCompletedCleanup();
-int snapshotOrRestoreDeUserData();
+void OnAllPackagesReady();
+void OnBootCompleted();
+void BootCompletedCleanup();
+int SnapshotOrRestoreDeUserData();
-int unmountAll();
+int UnmountAll();
android::base::Result<MountedApexDatabase::MountedApexData>
-getTempMountedApexData(const std::string& package);
+GetTempMountedApexData(const std::string& package);
// Optimistically tries to remount as many APEX packages as possible.
// For more documentation see corresponding binder call in IApexService.aidl.
-android::base::Result<void> remountPackages();
+android::base::Result<void> RemountPackages();
} // namespace apex
} // namespace android
diff --git a/apexd/apexd_checkpoint.h b/apexd/apexd_checkpoint.h
index 7177c04..2b4c3a1 100644
--- a/apexd/apexd_checkpoint.h
+++ b/apexd/apexd_checkpoint.h
@@ -32,7 +32,7 @@
virtual android::base::Result<bool> NeedsCheckpoint() = 0;
virtual android::base::Result<bool> NeedsRollback() = 0;
- virtual android::base::Result<void> StartCheckpoint(int32_t numRetries) = 0;
+ virtual android::base::Result<void> StartCheckpoint(int32_t num_retries) = 0;
virtual android::base::Result<void> AbortChanges(const std::string& msg,
bool retry) = 0;
diff --git a/apexd/apexd_checkpoint_vold.cpp b/apexd/apexd_checkpoint_vold.cpp
index ca29209..8a8d0ff 100644
--- a/apexd/apexd_checkpoint_vold.cpp
+++ b/apexd/apexd_checkpoint_vold.cpp
@@ -31,11 +31,11 @@
namespace apex {
Result<VoldCheckpointInterface> VoldCheckpointInterface::Create() {
- auto voldService =
+ auto vold_service =
defaultServiceManager()->getService(android::String16("vold"));
- if (voldService != nullptr) {
+ if (vold_service != nullptr) {
return VoldCheckpointInterface(
- android::interface_cast<android::os::IVold>(voldService));
+ android::interface_cast<android::os::IVold>(vold_service));
}
return Errorf("Failed to retrieve vold service.");
}
@@ -91,9 +91,10 @@
return false;
}
-Result<void> VoldCheckpointInterface::StartCheckpoint(int32_t numRetries) {
+Result<void> VoldCheckpointInterface::StartCheckpoint(int32_t num_retries) {
if (supports_fs_checkpoints_) {
- android::binder::Status status = vold_service_->startCheckpoint(numRetries);
+ android::binder::Status status =
+ vold_service_->startCheckpoint(num_retries);
if (!status.isOk()) {
return Error() << status.toString8().c_str();
}
diff --git a/apexd/apexd_checkpoint_vold.h b/apexd/apexd_checkpoint_vold.h
index dbd190d..f547532 100644
--- a/apexd/apexd_checkpoint_vold.h
+++ b/apexd/apexd_checkpoint_vold.h
@@ -44,7 +44,7 @@
android::base::Result<void> StartCheckpoint(int32_t retry) override;
android::base::Result<void> AbortChanges(const std::string& msg,
- bool numRetries) override;
+ bool num_retries) override;
static android::base::Result<VoldCheckpointInterface> Create();
diff --git a/apexd/apexd_lifecycle.cpp b/apexd/apexd_lifecycle.cpp
index c44ca5a..84918f9 100644
--- a/apexd/apexd_lifecycle.cpp
+++ b/apexd/apexd_lifecycle.cpp
@@ -30,12 +30,12 @@
namespace android {
namespace apex {
-bool ApexdLifecycle::isBooting() {
+bool ApexdLifecycle::IsBooting() {
auto status = GetProperty(kApexStatusSysprop, "");
return status != kApexStatusReady && status != kApexStatusActivated;
}
-void ApexdLifecycle::waitForBootStatus(
+void ApexdLifecycle::WaitForBootStatus(
Result<void> (&revert_fn)(const std::string&)) {
while (!boot_completed_) {
// Check for change in either crashing property or sys.boot_completed
@@ -66,7 +66,7 @@
}
}
-void ApexdLifecycle::markBootCompleted() { boot_completed_ = true; }
+void ApexdLifecycle::MarkBootCompleted() { boot_completed_ = true; }
} // namespace apex
} // namespace android
diff --git a/apexd/apexd_lifecycle.h b/apexd/apexd_lifecycle.h
index bab0a05..5a2224f 100644
--- a/apexd/apexd_lifecycle.h
+++ b/apexd/apexd_lifecycle.h
@@ -33,13 +33,13 @@
ApexdLifecycle& operator=(ApexdLifecycle&&) = delete;
public:
- static ApexdLifecycle& getInstance() {
+ static ApexdLifecycle& GetInstance() {
static ApexdLifecycle instance;
return instance;
}
- bool isBooting();
- void markBootCompleted();
- void waitForBootStatus(
+ bool IsBooting();
+ void MarkBootCompleted();
+ void WaitForBootStatus(
android::base::Result<void> (&rollback_fn)(const std::string&));
};
} // namespace apex
diff --git a/apexd/apexd_loop.cpp b/apexd/apexd_loop.cpp
index 4ab4016..8a23fbf 100644
--- a/apexd/apexd_loop.cpp
+++ b/apexd/apexd_loop.cpp
@@ -32,6 +32,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
@@ -42,6 +43,7 @@
using android::base::Basename;
using android::base::Error;
using android::base::GetBoolProperty;
+using android::base::ParseUint;
using android::base::Result;
using android::base::StartsWith;
using android::base::StringPrintf;
@@ -83,7 +85,7 @@
}
}
-Result<void> configureReadAhead(const std::string& device_path) {
+Result<void> ConfigureReadAhead(const std::string& device_path) {
CHECK(StartsWith(device_path, "/dev/"));
std::string device_name = Basename(device_path);
@@ -103,10 +105,10 @@
return {};
}
-Result<void> preAllocateLoopDevices(size_t num) {
- Result<void> loopReady = WaitForFile("/dev/loop-control", 20s);
- if (!loopReady.ok()) {
- return loopReady;
+Result<void> PreAllocateLoopDevices(size_t num) {
+ Result<void> loop_ready = WaitForFile("/dev/loop-control", 20s);
+ if (!loop_ready.ok()) {
+ return loop_ready;
}
unique_fd ctl_fd(
TEMP_FAILURE_RETRY(open("/dev/loop-control", O_RDWR | O_CLOEXEC)));
@@ -114,13 +116,30 @@
return ErrnoError() << "Failed to open loop-control";
}
+ bool found = false;
+ size_t start_id = 0;
+ constexpr const char* kLoopPrefix = "loop";
+ WalkDir("/dev/block", [&](const std::filesystem::directory_entry& entry) {
+ std::string devname = entry.path().filename().string();
+ if (StartsWith(devname, kLoopPrefix)) {
+ size_t id;
+ auto parse_ok = ParseUint(
+ devname.substr(std::char_traits<char>::length(kLoopPrefix)), &id);
+ if (parse_ok && id > start_id) {
+ start_id = id;
+ found = true;
+ }
+ }
+ });
+ if (found) ++start_id;
+
// Assumption: loop device ID [0..num) is valid.
// This is because pre-allocation happens during bootstrap.
// Anyway Kernel pre-allocated loop devices
// as many as CONFIG_BLK_DEV_LOOP_MIN_COUNT,
// Within the amount of kernel-pre-allocation,
// LOOP_CTL_ADD will fail with EEXIST
- for (size_t id = 0ul; id < num; ++id) {
+ for (size_t id = start_id; id < num + start_id; ++id) {
int ret = ioctl(ctl_fd.get(), LOOP_CTL_ADD, id);
if (ret < 0 && errno != EEXIST) {
return ErrnoError() << "Failed LOOP_CTL_ADD";
@@ -133,17 +152,17 @@
// just optimistally hope that they are all created when we actually
// access them for activating APEXes. If the dev nodes are not ready
// even then, we wait 50ms and warning message will be printed (see below
- // createLoopDevice()).
+ // CreateLoopDevice()).
LOG(INFO) << "Pre-allocated " << num << " loopback devices";
return {};
}
-Result<void> configureLoopDevice(const int device_fd, const std::string& target,
- const int32_t imageOffset,
- const size_t imageSize) {
- static bool useLoopConfigure;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [&]() {
+Result<void> ConfigureLoopDevice(const int device_fd, const std::string& target,
+ const int32_t image_offset,
+ const size_t image_size) {
+ static bool use_loop_configure;
+ static std::once_flag once_flag;
+ std::call_once(once_flag, [&]() {
// LOOP_CONFIGURE is a new ioctl in Linux 5.8 (and backported in Android
// common) that allows atomically configuring a loop device. It is a lot
// faster than the traditional LOOP_SET_FD/LOOP_SET_STATUS64 combo, but
@@ -154,7 +173,7 @@
config.fd = -1;
if (ioctl(device_fd, LOOP_CONFIGURE, &config) == -1 && errno == EBADF) {
// If the IOCTL exists, it will fail with EBADF for the -1 fd
- useLoopConfigure = true;
+ use_loop_configure = true;
}
});
@@ -188,10 +207,10 @@
struct loop_info64 li;
memset(&li, 0, sizeof(li));
strlcpy((char*)li.lo_crypt_name, kApexLoopIdPrefix, LO_NAME_SIZE);
- li.lo_offset = imageOffset;
- li.lo_sizelimit = imageSize;
+ li.lo_offset = image_offset;
+ li.lo_sizelimit = image_size;
- if (useLoopConfigure) {
+ if (use_loop_configure) {
struct loop_config config;
memset(&config, 0, sizeof(config));
li.lo_flags |= LO_FLAGS_DIRECT_IO;
@@ -279,9 +298,9 @@
return Error() << "Faled to open loopback device " << num;
}
-Result<LoopbackDeviceUniqueFd> createLoopDevice(const std::string& target,
- const int32_t imageOffset,
- const size_t imageSize) {
+Result<LoopbackDeviceUniqueFd> CreateLoopDevice(const std::string& target,
+ const int32_t image_offset,
+ const size_t image_size) {
unique_fd ctl_fd(open("/dev/loop-control", O_RDWR | O_CLOEXEC));
if (ctl_fd.get() == -1) {
return ErrnoError() << "Failed to open loop-control";
@@ -298,15 +317,15 @@
}
CHECK_NE(loop_device->device_fd.get(), -1);
- Result<void> configureStatus = configureLoopDevice(
- loop_device->device_fd.get(), target, imageOffset, imageSize);
+ Result<void> configureStatus = ConfigureLoopDevice(
+ loop_device->device_fd.get(), target, image_offset, image_size);
if (!configureStatus.ok()) {
return configureStatus.error();
}
- Result<void> readAheadStatus = configureReadAhead(loop_device->name);
- if (!readAheadStatus.ok()) {
- return readAheadStatus.error();
+ Result<void> read_ahead_status = ConfigureReadAhead(loop_device->name);
+ if (!read_ahead_status.ok()) {
+ return read_ahead_status.error();
}
return loop_device;
diff --git a/apexd/apexd_loop.h b/apexd/apexd_loop.h
index 8341675..1dbab21 100644
--- a/apexd/apexd_loop.h
+++ b/apexd/apexd_loop.h
@@ -52,16 +52,16 @@
void CloseGood() { device_fd.reset(-1); }
- int get() { return device_fd.get(); }
+ int Get() { return device_fd.get(); }
};
-android::base::Result<void> configureReadAhead(const std::string& device_path);
+android::base::Result<void> ConfigureReadAhead(const std::string& device_path);
-android::base::Result<void> preAllocateLoopDevices(size_t num);
+android::base::Result<void> PreAllocateLoopDevices(size_t num);
-android::base::Result<LoopbackDeviceUniqueFd> createLoopDevice(
- const std::string& target, const int32_t imageOffset,
- const size_t imageSize);
+android::base::Result<LoopbackDeviceUniqueFd> CreateLoopDevice(
+ const std::string& target, const int32_t image_offset,
+ const size_t image_size);
using DestroyLoopFn =
std::function<void(const std::string&, const std::string&)>;
diff --git a/apexd/apexd_main.cpp b/apexd/apexd_main.cpp
index 93d0a6f..0f13db1 100644
--- a/apexd/apexd_main.cpp
+++ b/apexd/apexd_main.cpp
@@ -32,7 +32,7 @@
namespace {
android::apex::ApexdLifecycle& lifecycle =
- android::apex::ApexdLifecycle::getInstance();
+ android::apex::ApexdLifecycle::GetInstance();
int HandleSubcommand(char** argv) {
if (strcmp("--pre-install", argv[1]) == 0) {
@@ -47,12 +47,12 @@
if (strcmp("--bootstrap", argv[1]) == 0) {
LOG(INFO) << "Bootstrap subcommand detected";
- return android::apex::onBootstrap();
+ return android::apex::OnBootstrap();
}
if (strcmp("--unmount-all", argv[1]) == 0) {
LOG(INFO) << "Unmount all subcommand detected";
- return android::apex::unmountAll();
+ return android::apex::UnmountAll();
}
if (strcmp("--snapshotde", argv[1]) == 0) {
@@ -65,16 +65,16 @@
LOG(ERROR) << "Could not retrieve vold service: "
<< vold_service_st.error();
} else {
- android::apex::initializeVold(&*vold_service_st);
+ android::apex::InitializeVold(&*vold_service_st);
}
- int result = android::apex::snapshotOrRestoreDeUserData();
+ int result = android::apex::SnapshotOrRestoreDeUserData();
if (result == 0) {
// Notify other components (e.g. init) that all APEXs are ready to be used
// Note that it's important that the binder service is registered at this
// point, since other system services might depend on it.
- android::apex::onAllPackagesReady();
+ android::apex::OnAllPackagesReady();
}
return result;
}
@@ -116,10 +116,10 @@
LOG(INFO) << "This device does not support updatable APEX. Exiting";
if (!has_subcommand) {
// mark apexd as activated so that init can proceed
- android::apex::onAllPackagesActivated(/*is_bootstrap=*/false);
+ android::apex::OnAllPackagesActivated(/*is_bootstrap=*/false);
} else if (strcmp("--snapshotde", argv[1]) == 0) {
// mark apexd as ready
- android::apex::onAllPackagesReady();
+ android::apex::OnAllPackagesReady();
}
return 0;
}
@@ -137,15 +137,15 @@
} else {
vold_service = &*vold_service_st;
}
- android::apex::initialize(vold_service);
+ android::apex::Initialize(vold_service);
- bool booting = lifecycle.isBooting();
+ bool booting = lifecycle.IsBooting();
if (booting) {
- if (auto res = android::apex::migrateSessionsDirIfNeeded(); !res.ok()) {
+ if (auto res = android::apex::MigrateSessionsDirIfNeeded(); !res.ok()) {
LOG(ERROR) << "Failed to migrate sessions to /metadata partition : "
<< res.error();
}
- android::apex::onStart();
+ android::apex::OnStart();
}
android::apex::binder::CreateAndRegisterService();
android::apex::binder::StartThreadPool();
@@ -157,8 +157,8 @@
// themselves should wait for the ready status instead, which is set when
// the "--snapshotde" subcommand is received and snapshot/restore is
// complete.
- android::apex::onAllPackagesActivated(/*is_bootstrap=*/false);
- lifecycle.waitForBootStatus(android::apex::revertActiveSessionsAndReboot);
+ android::apex::OnAllPackagesActivated(/*is_bootstrap=*/false);
+ lifecycle.WaitForBootStatus(android::apex::RevertActiveSessionsAndReboot);
}
android::apex::binder::AllowServiceShutdown();
diff --git a/apexd/apexd_private.h b/apexd/apexd_private.h
index 2c11327..23c6267 100644
--- a/apexd/apexd_private.h
+++ b/apexd/apexd_private.h
@@ -40,7 +40,7 @@
android::base::Result<void> BindMount(const std::string& target,
const std::string& source);
android::base::Result<MountedApexDatabase::MountedApexData>
-getTempMountedApexData(const std::string& package);
+GetTempMountedApexData(const std::string& package);
android::base::Result<void> UnmountTempMount(const ApexFile& apex);
} // namespace apexd_private
diff --git a/apexd/apexd_rollback_utils.h b/apexd/apexd_rollback_utils.h
index 9990be2..afb6275 100644
--- a/apexd/apexd_rollback_utils.h
+++ b/apexd/apexd_rollback_utils.h
@@ -40,7 +40,7 @@
* path. Note that this will fail if run before APEXes are mounted, due to a
* dependency on runtime.
*/
-int32_t copy_directory_recursive(const char* from, const char* to) {
+int32_t CopyDirectoryRecursive(const char* from, const char* to) {
const char* const argv[] = {
kCpPath,
"-F", /* delete any existing destination file first
@@ -83,7 +83,7 @@
};
auto scope_guard = android::base::make_scope_guard(deleter);
- int rc = copy_directory_recursive(from_path.c_str(), to_path.c_str());
+ int rc = CopyDirectoryRecursive(from_path.c_str(), to_path.c_str());
if (rc != 0) {
return Error() << "Failed to copy from [" << from_path << "] to ["
<< to_path << "]";
diff --git a/apexd/apexd_session.cpp b/apexd/apexd_session.cpp
index 145cd5a..185b0ed 100644
--- a/apexd/apexd_session.cpp
+++ b/apexd/apexd_session.cpp
@@ -76,7 +76,7 @@
SessionState state;
// Create session directory
std::string session_dir = GetSessionsDir() + "/" + std::to_string(session_id);
- if (auto status = createDirIfNeeded(session_dir, 0700); !status.ok()) {
+ if (auto status = CreateDirIfNeeded(session_dir, 0700); !status.ok()) {
return status.error();
}
state.set_id(session_id);
@@ -86,12 +86,12 @@
Result<ApexSession> ApexSession::GetSessionFromFile(const std::string& path) {
SessionState state;
- std::fstream stateFile(path, std::ios::in | std::ios::binary);
- if (!stateFile) {
+ std::fstream state_file(path, std::ios::in | std::ios::binary);
+ if (!state_file) {
return Error() << "Failed to open " << path;
}
- if (!state.ParseFromIstream(&stateFile)) {
+ if (!state.ParseFromIstream(&state_file)) {
return Error() << "Failed to parse " << path;
}
@@ -108,19 +108,19 @@
std::vector<ApexSession> ApexSession::GetSessions() {
std::vector<ApexSession> sessions;
- Result<std::vector<std::string>> sessionPaths = ReadDir(
+ Result<std::vector<std::string>> session_paths = ReadDir(
GetSessionsDir(), [](const std::filesystem::directory_entry& entry) {
std::error_code ec;
return entry.is_directory(ec);
});
- if (!sessionPaths.ok()) {
+ if (!session_paths.ok()) {
return sessions;
}
- for (const std::string& sessionDirPath : *sessionPaths) {
+ for (const std::string& session_dir_path : *session_paths) {
// Try to read session state
- auto session = GetSessionFromFile(sessionDirPath + "/" + kStateFileName);
+ auto session = GetSessionFromFile(session_dir_path + "/" + kStateFileName);
if (!session.ok()) {
LOG(WARNING) << session.error();
continue;
@@ -144,13 +144,13 @@
std::vector<ApexSession> ApexSession::GetActiveSessions() {
auto sessions = GetSessions();
- std::vector<ApexSession> activeSessions;
+ std::vector<ApexSession> active_sessions;
for (const ApexSession& session : sessions) {
if (!session.IsFinalized() && session.GetState() != SessionState::UNKNOWN) {
- activeSessions.push_back(session);
+ active_sessions.push_back(session);
}
}
- return activeSessions;
+ return active_sessions;
}
SessionState::State ApexSession::GetState() const { return state_.state(); }
diff --git a/apexd/apexd_session_test.cpp b/apexd/apexd_session_test.cpp
index bec0561..573b4d5 100644
--- a/apexd/apexd_session_test.cpp
+++ b/apexd/apexd_session_test.cpp
@@ -71,7 +71,7 @@
public:
TestApexSession(int id, const SessionState::State& state) {
path_ = "/data/apex/sessions/" + std::to_string(id);
- if (auto status = createDirIfNeeded(path_, 0700); !status.ok()) {
+ if (auto status = CreateDirIfNeeded(path_, 0700); !status.ok()) {
ADD_FAILURE() << "Failed to create " << path_ << " : "
<< status.error();
}
diff --git a/apexd/apexd_utils.h b/apexd/apexd_utils.h
index e970404..e268f59 100644
--- a/apexd/apexd_utils.h
+++ b/apexd/apexd_utils.h
@@ -18,6 +18,7 @@
#define ANDROID_APEXD_APEXD_UTILS_H_
#include <chrono>
+#include <cstdint>
#include <filesystem>
#include <string>
#include <thread>
@@ -126,7 +127,7 @@
return res.ok() && res->empty();
}
-inline Result<void> createDirIfNeeded(const std::string& path, mode_t mode) {
+inline Result<void> CreateDirIfNeeded(const std::string& path, mode_t mode) {
struct stat stat_data;
if (stat(path.c_str(), &stat_data) != 0) {
@@ -175,16 +176,6 @@
return {};
}
-inline Result<ino_t> get_path_inode(const std::string& path) {
- struct stat buf;
- memset(&buf, 0, sizeof(buf));
- if (stat(path.c_str(), &buf) != 0) {
- return ErrnoError() << "Failed to stat " << path;
- } else {
- return buf.st_ino;
- }
-}
-
inline Result<bool> PathExists(const std::string& path) {
namespace fs = std::filesystem;
@@ -345,6 +336,17 @@
return {};
}
+inline Result<uintmax_t> GetFileSize(const std::string& file_path) {
+ std::error_code ec;
+ auto value = std::filesystem::file_size(file_path, ec);
+ if (ec) {
+ return Error() << "Failed to get file size of " << file_path << " : "
+ << ec.message();
+ }
+
+ return value;
+}
+
} // namespace apex
} // namespace android
diff --git a/apexd/apexd_verity.cpp b/apexd/apexd_verity.cpp
index 052550c..e0975e0 100644
--- a/apexd/apexd_verity.cpp
+++ b/apexd/apexd_verity.cpp
@@ -151,7 +151,7 @@
Result<PrepareHashTreeResult> PrepareHashTree(
const ApexFile& apex, const ApexVerityData& verity_data,
const std::string& hashtree_file) {
- if (auto st = createDirIfNeeded(kApexHashTreeDir, 0700); !st.ok()) {
+ if (auto st = CreateDirIfNeeded(kApexHashTreeDir, 0700); !st.ok()) {
return st.error();
}
bool should_regenerate_hashtree = false;
diff --git a/apexd/apexservice.cpp b/apexd/apexservice.cpp
index 1729bff..c0cb2ff 100644
--- a/apexd/apexservice.cpp
+++ b/apexd/apexservice.cpp
@@ -79,10 +79,10 @@
BinderStatus getSessions(std::vector<ApexSessionInfo>* aidl_return) override;
BinderStatus getStagedSessionInfo(
int session_id, ApexSessionInfo* apex_session_info) override;
- BinderStatus activatePackage(const std::string& packagePath) override;
- BinderStatus deactivatePackage(const std::string& packagePath) override;
+ BinderStatus activatePackage(const std::string& package_path) override;
+ BinderStatus deactivatePackage(const std::string& package_path) override;
BinderStatus getActivePackages(std::vector<ApexInfo>* aidl_return) override;
- BinderStatus getActivePackage(const std::string& packageName,
+ BinderStatus getActivePackage(const std::string& package_name,
ApexInfo* aidl_return) override;
BinderStatus getAllPackages(std::vector<ApexInfo>* aidl_return) override;
BinderStatus preinstallPackages(
@@ -93,11 +93,11 @@
BinderStatus revertActiveSessions() override;
BinderStatus resumeRevertIfNeeded() override;
BinderStatus snapshotCeData(int user_id, int rollback_id,
- const std::string& apex_name,
- int64_t* _aidl_return) override;
+ const std::string& apex_name) override;
BinderStatus restoreCeData(int user_id, int rollback_id,
const std::string& apex_name) override;
BinderStatus destroyDeSnapshots(int rollback_id) override;
+ BinderStatus destroyCeSnapshots(int user_id, int rollback_id) override;
BinderStatus destroyCeSnapshotsNotSpecified(
int user_id, const std::vector<int>& retain_rollback_ids) override;
BinderStatus remountPackages() override;
@@ -124,14 +124,14 @@
}
BinderStatus ApexService::stagePackages(const std::vector<std::string>& paths) {
- BinderStatus debugCheck = CheckDebuggable("stagePackages");
- if (!debugCheck.isOk()) {
- return debugCheck;
+ BinderStatus debug_check = CheckDebuggable("stagePackages");
+ if (!debug_check.isOk()) {
+ return debug_check;
}
LOG(DEBUG) << "stagePackages() received by ApexService, paths "
<< android::base::Join(paths, ',');
- Result<void> res = ::android::apex::stagePackages(paths);
+ Result<void> res = ::android::apex::StagePackages(paths);
if (res.ok()) {
return BinderStatus::ok();
@@ -146,7 +146,7 @@
BinderStatus ApexService::unstagePackages(
const std::vector<std::string>& paths) {
- Result<void> res = ::android::apex::unstagePackages(paths);
+ Result<void> res = ::android::apex::UnstagePackages(paths);
if (res.ok()) {
return BinderStatus::ok();
}
@@ -164,7 +164,7 @@
<< params.sessionId << " child sessions: ["
<< android::base::Join(params.childSessionIds, ',') << "]";
- Result<std::vector<ApexFile>> packages = ::android::apex::submitStagedSession(
+ Result<std::vector<ApexFile>> packages = ::android::apex::SubmitStagedSession(
params.sessionId, params.childSessionIds, params.hasRollbackEnabled,
params.isRollback, params.rollbackId);
if (!packages.ok()) {
@@ -188,7 +188,7 @@
BinderStatus ApexService::markStagedSessionReady(int session_id) {
LOG(DEBUG) << "markStagedSessionReady() received by ApexService, session id "
<< session_id;
- Result<void> success = ::android::apex::markStagedSessionReady(session_id);
+ Result<void> success = ::android::apex::MarkStagedSessionReady(session_id);
if (!success.ok()) {
LOG(ERROR) << "Failed to mark session id " << session_id
<< " as ready: " << success.error();
@@ -203,7 +203,7 @@
LOG(DEBUG)
<< "markStagedSessionSuccessful() received by ApexService, session id "
<< session_id;
- Result<void> ret = ::android::apex::markStagedSessionSuccessful(session_id);
+ Result<void> ret = ::android::apex::MarkStagedSessionSuccessful(session_id);
if (!ret.ok()) {
LOG(ERROR) << "Failed to mark session " << session_id
<< " as SUCCESS: " << ret.error();
@@ -215,7 +215,7 @@
}
BinderStatus ApexService::markBootCompleted() {
- ::android::apex::onBootCompleted();
+ ::android::apex::OnBootCompleted();
return BinderStatus::ok();
}
@@ -232,7 +232,7 @@
session_info->isRevertFailed = false;
}
-void convertToApexSessionInfo(const ApexSession& session,
+void ConvertToApexSessionInfo(const ApexSession& session,
ApexSessionInfo* session_info) {
using SessionState = ::apex::proto::SessionState;
@@ -272,7 +272,7 @@
}
}
-static ApexInfo getApexInfo(const ApexFile& package) {
+static ApexInfo GetApexInfo(const ApexFile& package) {
auto& instance = ApexPreinstalledData::GetInstance();
ApexInfo out;
out.moduleName = package.GetManifest().name();
@@ -281,15 +281,15 @@
out.versionName = package.GetManifest().versionname();
out.isFactory = instance.IsPreInstalledApex(package);
out.isActive = false;
- Result<std::string> preinstalledPath =
+ Result<std::string> preinstalled_path =
instance.GetPreinstalledPath(package.GetManifest().name());
- if (preinstalledPath.ok()) {
- out.preinstalledModulePath = *preinstalledPath;
+ if (preinstalled_path.ok()) {
+ out.preinstalledModulePath = *preinstalled_path;
}
return out;
}
-static std::string toString(const ApexInfo& package) {
+static std::string ToString(const ApexInfo& package) {
std::string msg = StringLog()
<< "Module: " << package.moduleName
<< " Version: " << package.versionCode
@@ -305,9 +305,9 @@
std::vector<ApexSessionInfo>* aidl_return) {
auto sessions = ApexSession::GetSessions();
for (const auto& session : sessions) {
- ApexSessionInfo sessionInfo;
- convertToApexSessionInfo(session, &sessionInfo);
- aidl_return->push_back(sessionInfo);
+ ApexSessionInfo session_info;
+ ConvertToApexSessionInfo(session, &session_info);
+ aidl_return->push_back(session_info);
}
return BinderStatus::ok();
@@ -325,48 +325,48 @@
return BinderStatus::ok();
}
- convertToApexSessionInfo(*session, apex_session_info);
+ ConvertToApexSessionInfo(*session, apex_session_info);
return BinderStatus::ok();
}
-BinderStatus ApexService::activatePackage(const std::string& packagePath) {
- BinderStatus debugCheck = CheckDebuggable("activatePackage");
- if (!debugCheck.isOk()) {
- return debugCheck;
+BinderStatus ApexService::activatePackage(const std::string& package_path) {
+ BinderStatus debug_check = CheckDebuggable("activatePackage");
+ if (!debug_check.isOk()) {
+ return debug_check;
}
LOG(DEBUG) << "activatePackage() received by ApexService, path "
- << packagePath;
+ << package_path;
- Result<void> res = ::android::apex::activatePackage(packagePath);
+ Result<void> res = ::android::apex::ActivatePackage(package_path);
if (res.ok()) {
return BinderStatus::ok();
}
- LOG(ERROR) << "Failed to activate " << packagePath << ": " << res.error();
+ LOG(ERROR) << "Failed to activate " << package_path << ": " << res.error();
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
String8(res.error().message().c_str()));
}
-BinderStatus ApexService::deactivatePackage(const std::string& packagePath) {
- BinderStatus debugCheck = CheckDebuggable("deactivatePackage");
- if (!debugCheck.isOk()) {
- return debugCheck;
+BinderStatus ApexService::deactivatePackage(const std::string& package_path) {
+ BinderStatus debug_check = CheckDebuggable("deactivatePackage");
+ if (!debug_check.isOk()) {
+ return debug_check;
}
LOG(DEBUG) << "deactivatePackage() received by ApexService, path "
- << packagePath;
+ << package_path;
- Result<void> res = ::android::apex::deactivatePackage(packagePath);
+ Result<void> res = ::android::apex::DeactivatePackage(package_path);
if (res.ok()) {
return BinderStatus::ok();
}
- LOG(ERROR) << "Failed to deactivate " << packagePath << ": " << res.error();
+ LOG(ERROR) << "Failed to deactivate " << package_path << ": " << res.error();
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
String8(res.error().message().c_str()));
@@ -374,31 +374,31 @@
BinderStatus ApexService::getActivePackages(
std::vector<ApexInfo>* aidl_return) {
- auto packages = ::android::apex::getActivePackages();
+ auto packages = ::android::apex::GetActivePackages();
for (const auto& package : packages) {
- ApexInfo apexInfo = getApexInfo(package);
- apexInfo.isActive = true;
- aidl_return->push_back(std::move(apexInfo));
+ ApexInfo apex_info = GetApexInfo(package);
+ apex_info.isActive = true;
+ aidl_return->push_back(std::move(apex_info));
}
return BinderStatus::ok();
}
-BinderStatus ApexService::getActivePackage(const std::string& packageName,
+BinderStatus ApexService::getActivePackage(const std::string& package_name,
ApexInfo* aidl_return) {
- Result<ApexFile> apex = ::android::apex::getActivePackage(packageName);
+ Result<ApexFile> apex = ::android::apex::GetActivePackage(package_name);
if (apex.ok()) {
- *aidl_return = getApexInfo(*apex);
+ *aidl_return = GetApexInfo(*apex);
aidl_return->isActive = true;
}
return BinderStatus::ok();
}
BinderStatus ApexService::getAllPackages(std::vector<ApexInfo>* aidl_return) {
- const auto& active = ::android::apex::getActivePackages();
- const auto& factory = ::android::apex::getFactoryPackages();
+ const auto& active = ::android::apex::GetActivePackages();
+ const auto& factory = ::android::apex::GetFactoryPackages();
for (const ApexFile& pkg : active) {
- ApexInfo apex_info = getApexInfo(pkg);
+ ApexInfo apex_info = GetApexInfo(pkg);
apex_info.isActive = true;
aidl_return->push_back(std::move(apex_info));
}
@@ -407,7 +407,7 @@
return o.GetPath() == pkg.GetPath();
};
if (std::find_if(active.begin(), active.end(), same_path) == active.end()) {
- aidl_return->push_back(getApexInfo(pkg));
+ aidl_return->push_back(GetApexInfo(pkg));
}
}
return BinderStatus::ok();
@@ -415,12 +415,12 @@
BinderStatus ApexService::preinstallPackages(
const std::vector<std::string>& paths) {
- BinderStatus debugCheck = CheckDebuggable("preinstallPackages");
- if (!debugCheck.isOk()) {
- return debugCheck;
+ BinderStatus debug_check = CheckDebuggable("preinstallPackages");
+ if (!debug_check.isOk()) {
+ return debug_check;
}
- Result<void> res = ::android::apex::preinstallPackages(paths);
+ Result<void> res = ::android::apex::PreinstallPackages(paths);
if (res.ok()) {
return BinderStatus::ok();
}
@@ -434,12 +434,12 @@
BinderStatus ApexService::postinstallPackages(
const std::vector<std::string>& paths) {
- BinderStatus debugCheck = CheckDebuggable("postinstallPackages");
- if (!debugCheck.isOk()) {
- return debugCheck;
+ BinderStatus debug_check = CheckDebuggable("postinstallPackages");
+ if (!debug_check.isOk()) {
+ return debug_check;
}
- Result<void> res = ::android::apex::postinstallPackages(paths);
+ Result<void> res = ::android::apex::PostinstallPackages(paths);
if (res.ok()) {
return BinderStatus::ok();
}
@@ -453,7 +453,7 @@
BinderStatus ApexService::abortStagedSession(int session_id) {
LOG(DEBUG) << "abortStagedSession() received by ApexService.";
- Result<void> res = ::android::apex::abortStagedSession(session_id);
+ Result<void> res = ::android::apex::AbortStagedSession(session_id);
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_ILLEGAL_ARGUMENT,
@@ -464,7 +464,7 @@
BinderStatus ApexService::revertActiveSessions() {
LOG(DEBUG) << "revertActiveSessions() received by ApexService.";
- Result<void> res = ::android::apex::revertActiveSessions("");
+ Result<void> res = ::android::apex::RevertActiveSessions("");
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_ILLEGAL_ARGUMENT,
@@ -474,13 +474,13 @@
}
BinderStatus ApexService::resumeRevertIfNeeded() {
- BinderStatus debugCheck = CheckDebuggable("resumeRevertIfNeeded");
- if (!debugCheck.isOk()) {
- return debugCheck;
+ BinderStatus debug_check = CheckDebuggable("resumeRevertIfNeeded");
+ if (!debug_check.isOk()) {
+ return debug_check;
}
LOG(DEBUG) << "resumeRevertIfNeeded() received by ApexService.";
- Result<void> res = ::android::apex::resumeRevertIfNeeded();
+ Result<void> res = ::android::apex::ResumeRevertIfNeeded();
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_ILLEGAL_ARGUMENT,
@@ -490,17 +490,15 @@
}
BinderStatus ApexService::snapshotCeData(int user_id, int rollback_id,
- const std::string& apex_name,
- int64_t* _aidl_return) {
+ const std::string& apex_name) {
LOG(DEBUG) << "snapshotCeData() received by ApexService.";
- Result<ino_t> res =
- ::android::apex::snapshotCeData(user_id, rollback_id, apex_name);
+ Result<void> res =
+ ::android::apex::SnapshotCeData(user_id, rollback_id, apex_name);
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
String8(res.error().message().c_str()));
}
- *_aidl_return = static_cast<uint64_t>(*res);
return BinderStatus::ok();
}
@@ -508,7 +506,7 @@
const std::string& apex_name) {
LOG(DEBUG) << "restoreCeData() received by ApexService.";
Result<void> res =
- ::android::apex::restoreCeData(user_id, rollback_id, apex_name);
+ ::android::apex::RestoreCeData(user_id, rollback_id, apex_name);
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
@@ -519,7 +517,18 @@
BinderStatus ApexService::destroyDeSnapshots(int rollback_id) {
LOG(DEBUG) << "destroyDeSnapshots() received by ApexService.";
- Result<void> res = ::android::apex::destroyDeSnapshots(rollback_id);
+ Result<void> res = ::android::apex::DestroyDeSnapshots(rollback_id);
+ if (!res.ok()) {
+ return BinderStatus::fromExceptionCode(
+ BinderStatus::EX_SERVICE_SPECIFIC,
+ String8(res.error().message().c_str()));
+ }
+ return BinderStatus::ok();
+}
+
+BinderStatus ApexService::destroyCeSnapshots(int user_id, int rollback_id) {
+ LOG(DEBUG) << "destroyCeSnapshots() received by ApexService.";
+ Result<void> res = ::android::apex::DestroyCeSnapshots(user_id, rollback_id);
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
@@ -531,7 +540,7 @@
BinderStatus ApexService::destroyCeSnapshotsNotSpecified(
int user_id, const std::vector<int>& retain_rollback_ids) {
LOG(DEBUG) << "destroyCeSnapshotsNotSpecified() received by ApexService.";
- Result<void> res = ::android::apex::destroyCeSnapshotsNotSpecified(
+ Result<void> res = ::android::apex::DestroyCeSnapshotsNotSpecified(
user_id, retain_rollback_ids);
if (!res.ok()) {
return BinderStatus::fromExceptionCode(
@@ -549,7 +558,7 @@
if (auto root = CheckCallerIsRoot("remountPackages"); !root.isOk()) {
return root;
}
- if (auto res = ::android::apex::remountPackages(); !res.ok()) {
+ if (auto res = ::android::apex::RemountPackages(); !res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
String8(res.error().message().c_str()));
@@ -570,7 +579,7 @@
return root;
}
ApexPreinstalledData& instance = ApexPreinstalledData::GetInstance();
- if (auto res = instance.Initialize(paths); !res) {
+ if (auto res = instance.Initialize(paths); !res.ok()) {
return BinderStatus::fromExceptionCode(
BinderStatus::EX_SERVICE_SPECIFIC,
String8(res.error().message().c_str()));
@@ -590,16 +599,18 @@
for (int i = 0; i < argc && _aidl_data.dataAvail() > 0; i++) {
args.add(_aidl_data.readString16());
}
- sp<IBinder> unusedCallback;
- sp<IResultReceiver> resultReceiver;
+ sp<IBinder> unused_callback;
+ sp<IResultReceiver> result_receiver;
status_t status;
- if ((status = _aidl_data.readNullableStrongBinder(&unusedCallback)) != OK)
+ if ((status = _aidl_data.readNullableStrongBinder(&unused_callback)) !=
+ OK)
return status;
- if ((status = _aidl_data.readNullableStrongBinder(&resultReceiver)) != OK)
+ if ((status = _aidl_data.readNullableStrongBinder(&result_receiver)) !=
+ OK)
return status;
status = shellCommand(in, out, err, args);
- if (resultReceiver != nullptr) {
- resultReceiver->send(status);
+ if (result_receiver != nullptr) {
+ result_receiver->send(status);
}
return OK;
}
@@ -618,7 +629,7 @@
return BAD_VALUE;
} else {
for (const auto& item : list) {
- std::string msg = toString(item);
+ std::string msg = ToString(item);
dprintf(fd, "%s", msg.c_str());
}
}
@@ -662,25 +673,25 @@
}
log << "ApexService:" << std::endl
<< " help - display this help" << std::endl
- << " stagePackages [packagePath1] ([packagePath2]...) - stage "
+ << " stagePackages [package_path1] ([package_path2]...) - stage "
"multiple packages from the given path"
<< std::endl
- << " getActivePackage [packageName] - return info for active package "
+ << " getActivePackage [package_name] - return info for active package "
"with given name, if present"
<< std::endl
<< " getAllPackages - return the list of all packages" << std::endl
<< " getActivePackages - return the list of active packages"
<< std::endl
- << " activatePackage [packagePath] - activate package from the "
+ << " activatePackage [package_path] - activate package from the "
"given path"
<< std::endl
- << " deactivatePackage [packagePath] - deactivate package from the "
+ << " deactivatePackage [package_path] - deactivate package from the "
"given path"
<< std::endl
- << " preinstallPackages [packagePath1] ([packagePath2]...) - run "
+ << " preinstallPackages [package_path1] ([package_path2]...) - run "
"pre-install hooks of the given packages"
<< std::endl
- << " postinstallPackages [packagePath1] ([packagePath2]...) - run "
+ << " postinstallPackages [package_path1] ([package_path2]...) - run "
"post-install hooks of the given packages"
<< std::endl
<< " getStagedSessionInfo [sessionId] - displays information about a "
@@ -712,7 +723,7 @@
if (cmd == String16("stagePackages")) {
if (args.size() < 2) {
- print_help(err, "stagePackages requires at least one packagePath");
+ print_help(err, "stagePackages requires at least one package_path");
return BAD_VALUE;
}
std::vector<std::string> pkgs;
@@ -738,7 +749,7 @@
BinderStatus status = getAllPackages(&list);
if (status.isOk()) {
for (const auto& item : list) {
- std::string msg = toString(item);
+ std::string msg = ToString(item);
dprintf(out, "%s", msg.c_str());
}
return OK;
@@ -758,7 +769,7 @@
BinderStatus status = getActivePackages(&list);
if (status.isOk()) {
for (const auto& item : list) {
- std::string msg = toString(item);
+ std::string msg = ToString(item);
dprintf(out, "%s", msg.c_str());
}
return OK;
@@ -778,7 +789,7 @@
ApexInfo package;
BinderStatus status = getActivePackage(String8(args[1]).string(), &package);
if (status.isOk()) {
- std::string msg = toString(package);
+ std::string msg = ToString(package);
dprintf(out, "%s", msg.c_str());
return OK;
}
@@ -793,7 +804,7 @@
if (cmd == String16("activatePackage")) {
if (args.size() != 2) {
- print_help(err, "activatePackage requires one packagePath");
+ print_help(err, "activatePackage requires one package_path");
return BAD_VALUE;
}
BinderStatus status = activatePackage(String8(args[1]).string());
@@ -808,7 +819,7 @@
if (cmd == String16("deactivatePackage")) {
if (args.size() != 2) {
- print_help(err, "deactivatePackage requires one packagePath");
+ print_help(err, "deactivatePackage requires one package_path");
return BAD_VALUE;
}
BinderStatus status = deactivatePackage(String8(args[1]).string());
@@ -881,7 +892,7 @@
BinderStatus status = submitStagedSession(params, &list);
if (status.isOk()) {
for (const auto& item : list.apexInfos) {
- std::string msg = toString(item);
+ std::string msg = ToString(item);
dprintf(out, "%s", msg.c_str());
}
return OK;
@@ -897,7 +908,7 @@
if (args.size() < 2) {
print_help(err,
"preinstallPackages/postinstallPackages requires at least"
- " one packagePath");
+ " one package_path");
return BAD_VALUE;
}
std::vector<std::string> pkgs;
@@ -954,15 +965,15 @@
sp<ProcessState> ps(ProcessState::self());
// Create binder service and register with LazyServiceRegistrar
- sp<ApexService> apexService = new ApexService();
- auto lazyRegistrar = LazyServiceRegistrar::getInstance();
- lazyRegistrar.forcePersist(true);
- lazyRegistrar.registerService(apexService, kApexServiceName);
+ sp<ApexService> apex_service = new ApexService();
+ auto lazy_registrar = LazyServiceRegistrar::getInstance();
+ lazy_registrar.forcePersist(true);
+ lazy_registrar.registerService(apex_service, kApexServiceName);
}
void AllowServiceShutdown() {
- auto lazyRegistrar = LazyServiceRegistrar::getInstance();
- lazyRegistrar.forcePersist(false);
+ auto lazy_registrar = LazyServiceRegistrar::getInstance();
+ lazy_registrar.forcePersist(false);
}
void StartThreadPool() {
diff --git a/apexd/apexservice_test.cpp b/apexd/apexservice_test.cpp
index 4549939..1a1a1c1 100644
--- a/apexd/apexservice_test.cpp
+++ b/apexd/apexservice_test.cpp
@@ -849,18 +849,10 @@
ASSERT_TRUE(
RegularFileExists("/data/misc_ce/0/apexdata/apex.apexd_test/hello.txt"));
- int64_t result;
- service_->snapshotCeData(0, 123456, "apex.apexd_test", &result);
+ service_->snapshotCeData(0, 123456, "apex.apexd_test");
ASSERT_TRUE(RegularFileExists(
"/data/misc_ce/0/apexrollback/123456/apex.apexd_test/hello.txt"));
-
- // Check that the return value is the inode of the snapshot directory.
- struct stat buf;
- memset(&buf, 0, sizeof(buf));
- ASSERT_EQ(0,
- stat("/data/misc_ce/0/apexrollback/123456/apex.apexd_test", &buf));
- ASSERT_EQ(int64_t(buf.st_ino), result);
}
TEST_F(ApexServiceTest, RestoreCeData) {
@@ -923,6 +915,31 @@
ASSERT_FALSE(DirExists("/data/misc_de/0/apexrollback/123456"));
}
+TEST_F(ApexServiceTest, DestroyCeSnapshots) {
+ CreateDir("/data/misc_ce/0/apexrollback/123456");
+ CreateDir("/data/misc_ce/0/apexrollback/123456/apex.apexd_test");
+ CreateFile("/data/misc_ce/0/apexrollback/123456/apex.apexd_test/file.txt");
+
+ CreateDir("/data/misc_ce/0/apexrollback/77777");
+ CreateDir("/data/misc_ce/0/apexrollback/77777/apex.apexd_test");
+ CreateFile("/data/misc_ce/0/apexrollback/77777/apex.apexd_test/thing.txt");
+
+ ASSERT_TRUE(RegularFileExists(
+ "/data/misc_ce/0/apexrollback/123456/apex.apexd_test/file.txt"));
+ ASSERT_TRUE(RegularFileExists(
+ "/data/misc_ce/0/apexrollback/77777/apex.apexd_test/thing.txt"));
+
+ android::binder::Status st = service_->destroyCeSnapshots(0, 123456);
+ ASSERT_TRUE(IsOk(st));
+ // Should be OK if the directory doesn't exist.
+ st = service_->destroyCeSnapshots(1, 123456);
+ ASSERT_TRUE(IsOk(st));
+
+ ASSERT_TRUE(RegularFileExists(
+ "/data/misc_ce/0/apexrollback/77777/apex.apexd_test/thing.txt"));
+ ASSERT_FALSE(DirExists("/data/misc_ce/0/apexrollback/123456"));
+}
+
TEST_F(ApexServiceTest, DestroyCeSnapshotsNotSpecified) {
CreateDir("/data/misc_ce/0/apexrollback/123456");
CreateDir("/data/misc_ce/0/apexrollback/123456/apex.apexd_test");
@@ -1388,11 +1405,11 @@
}
TEST_F(ApexServiceTest, GetFactoryPackages) {
- Result<std::vector<ApexInfo>> factoryPackages = GetFactoryPackages();
- ASSERT_TRUE(IsOk(factoryPackages));
- ASSERT_TRUE(factoryPackages->size() > 0);
+ Result<std::vector<ApexInfo>> factory_packages = GetFactoryPackages();
+ ASSERT_TRUE(IsOk(factory_packages));
+ ASSERT_TRUE(factory_packages->size() > 0);
- for (const ApexInfo& package : *factoryPackages) {
+ for (const ApexInfo& package : *factory_packages) {
bool is_builtin = false;
for (const auto& dir : kApexPackageBuiltinDirs) {
if (StartsWith(package.modulePath, dir)) {
@@ -1404,46 +1421,48 @@
}
TEST_F(ApexServiceTest, NoPackagesAreBothActiveAndInactive) {
- Result<std::vector<ApexInfo>> activePackages = GetActivePackages();
- ASSERT_TRUE(IsOk(activePackages));
- ASSERT_TRUE(activePackages->size() > 0);
- Result<std::vector<ApexInfo>> inactivePackages = GetInactivePackages();
- ASSERT_TRUE(IsOk(inactivePackages));
- std::vector<std::string> activePackagesStrings =
- GetPackagesStrings(*activePackages);
- std::vector<std::string> inactivePackagesStrings =
- GetPackagesStrings(*inactivePackages);
- std::sort(activePackagesStrings.begin(), activePackagesStrings.end());
- std::sort(inactivePackagesStrings.begin(), inactivePackagesStrings.end());
+ Result<std::vector<ApexInfo>> active_packages = GetActivePackages();
+ ASSERT_TRUE(IsOk(active_packages));
+ ASSERT_TRUE(active_packages->size() > 0);
+ Result<std::vector<ApexInfo>> inactive_packages = GetInactivePackages();
+ ASSERT_TRUE(IsOk(inactive_packages));
+ std::vector<std::string> active_packages_strings =
+ GetPackagesStrings(*active_packages);
+ std::vector<std::string> inactive_packages_strings =
+ GetPackagesStrings(*inactive_packages);
+ std::sort(active_packages_strings.begin(), active_packages_strings.end());
+ std::sort(inactive_packages_strings.begin(), inactive_packages_strings.end());
std::vector<std::string> intersection;
std::set_intersection(
- activePackagesStrings.begin(), activePackagesStrings.end(),
- inactivePackagesStrings.begin(), inactivePackagesStrings.end(),
+ active_packages_strings.begin(), active_packages_strings.end(),
+ inactive_packages_strings.begin(), inactive_packages_strings.end(),
std::back_inserter(intersection));
ASSERT_THAT(intersection, SizeIs(0));
}
TEST_F(ApexServiceTest, GetAllPackages) {
- Result<std::vector<ApexInfo>> allPackages = GetAllPackages();
- ASSERT_TRUE(IsOk(allPackages));
- ASSERT_TRUE(allPackages->size() > 0);
- Result<std::vector<ApexInfo>> activePackages = GetActivePackages();
- std::vector<std::string> activeStrings = GetPackagesStrings(*activePackages);
- Result<std::vector<ApexInfo>> factoryPackages = GetFactoryPackages();
- std::vector<std::string> factoryStrings =
- GetPackagesStrings(*factoryPackages);
- for (ApexInfo& apexInfo : *allPackages) {
- std::string packageString = GetPackageString(apexInfo);
- bool shouldBeActive = std::find(activeStrings.begin(), activeStrings.end(),
- packageString) != activeStrings.end();
- bool shouldBeFactory =
- std::find(factoryStrings.begin(), factoryStrings.end(),
- packageString) != factoryStrings.end();
- ASSERT_EQ(shouldBeActive, apexInfo.isActive)
- << packageString << " should " << (shouldBeActive ? "" : "not ")
+ Result<std::vector<ApexInfo>> all_packages = GetAllPackages();
+ ASSERT_TRUE(IsOk(all_packages));
+ ASSERT_TRUE(all_packages->size() > 0);
+ Result<std::vector<ApexInfo>> active_packages = GetActivePackages();
+ std::vector<std::string> active_strings =
+ GetPackagesStrings(*active_packages);
+ Result<std::vector<ApexInfo>> factory_packages = GetFactoryPackages();
+ std::vector<std::string> factory_strings =
+ GetPackagesStrings(*factory_packages);
+ for (ApexInfo& apexInfo : *all_packages) {
+ std::string package_string = GetPackageString(apexInfo);
+ bool should_be_active =
+ std::find(active_strings.begin(), active_strings.end(),
+ package_string) != active_strings.end();
+ bool should_be_factory =
+ std::find(factory_strings.begin(), factory_strings.end(),
+ package_string) != factory_strings.end();
+ ASSERT_EQ(should_be_active, apexInfo.isActive)
+ << package_string << " should " << (should_be_active ? "" : "not ")
<< "be active";
- ASSERT_EQ(shouldBeFactory, apexInfo.isFactory)
- << packageString << " should " << (shouldBeFactory ? "" : "not ")
+ ASSERT_EQ(should_be_factory, apexInfo.isFactory)
+ << package_string << " should " << (should_be_factory ? "" : "not ")
<< "be factory";
}
}
@@ -2094,7 +2113,7 @@
}
// Make sure /data/apex/backups exists.
- ASSERT_TRUE(IsOk(createDirIfNeeded(std::string(kApexBackupDir), 0700)));
+ ASSERT_TRUE(IsOk(CreateDirIfNeeded(std::string(kApexBackupDir), 0700)));
// Create some bogus files in /data/apex/backups.
std::ofstream old_backup(StringPrintf("%s/file1", kApexBackupDir));
ASSERT_TRUE(old_backup.good());
@@ -2138,7 +2157,7 @@
// Make sure that /data/apex/active exists and is empty
ASSERT_TRUE(
- IsOk(createDirIfNeeded(std::string(kActiveApexPackagesDataDir), 0755)));
+ IsOk(CreateDirIfNeeded(std::string(kActiveApexPackagesDataDir), 0755)));
auto active_pkgs = ReadEntireDir(kActiveApexPackagesDataDir);
ASSERT_TRUE(IsOk(active_pkgs));
ASSERT_EQ(0u, active_pkgs->size());
@@ -2237,7 +2256,7 @@
void SetUp() override { ApexServiceTest::SetUp(); }
void PrepareBackup(const std::vector<std::string>& pkgs) {
- ASSERT_TRUE(IsOk(createDirIfNeeded(std::string(kApexBackupDir), 0700)));
+ ASSERT_TRUE(IsOk(CreateDirIfNeeded(std::string(kApexBackupDir), 0700)));
for (const auto& pkg : pkgs) {
PrepareTestApexForInstall installer(pkg);
ASSERT_TRUE(installer.Prepare()) << " failed to prepare " << pkg;
@@ -2451,7 +2470,7 @@
// TODO(ioffe): this is calling into internals of apexd which makes test quite
// britle. With some refactoring we should be able to call binder api, or
// make this a unit test of apexd.cpp.
- Result<void> res = ::android::apex::revertActiveSessions(native_process);
+ Result<void> res = ::android::apex::RevertActiveSessions(native_process);
session = ApexSession::GetSession(1543);
ASSERT_EQ(session->GetCrashingNativeProcess(), native_process);
}
diff --git a/docs/howto.md b/docs/howto.md
index 2c52b3a..d755f8a 100644
--- a/docs/howto.md
+++ b/docs/howto.md
@@ -107,7 +107,7 @@
Use this when a lib has to be accessed across the APEX boundary, e.g. between
APEXes or between an APEX and the platform.
-### `apex_available`
+### apex_available
Any module that is “included” (not just referenced) in an APEX either via the
direct dependency or the transitive dependency has to correctly set the
diff --git a/libs/libapexutil/apexutil.cpp b/libs/libapexutil/apexutil.cpp
index e0b0787..6203a3b 100644
--- a/libs/libapexutil/apexutil.cpp
+++ b/libs/libapexutil/apexutil.cpp
@@ -18,6 +18,7 @@
#include "apexutil.h"
#include <dirent.h>
+#include <string.h>
#include <memory>
@@ -67,6 +68,8 @@
continue;
if (strchr(entry->d_name, '@') != nullptr)
continue;
+ if (strcmp(entry->d_name, "sharedlibs") == 0)
+ continue;
std::string apex_path = apex_root + "/" + entry->d_name;
auto manifest = ParseApexManifest(apex_path + "/apex_manifest.pb");
if (manifest.ok()) {