diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 23:20:47 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 23:20:47 +0000 |
commit | 09b2af382f92e6691296440e9a1168d51d07a671 (patch) | |
tree | 8a2a92a862efe4d09774248c5b32a32d8bebc52b | |
parent | 901675fee4fcfe3612d30a49c0d6bc59009935d1 (diff) | |
parent | a9035b08ccd47626d8dd72287eb2decf42888ae0 (diff) | |
download | apex-sdk-release.tar.gz |
Snap for 11785460 from a9035b08ccd47626d8dd72287eb2decf42888ae0 to sdk-releasesdk-release
Change-Id: I518401ddff82879e7b9528682b83c4617e3af38c
-rw-r--r-- | apexd/Android.bp | 40 | ||||
-rw-r--r-- | apexd/apex_sha.cpp | 88 | ||||
-rw-r--r-- | apexd/apex_sha.h | 26 | ||||
-rw-r--r-- | apexd/apex_shim.cpp | 30 | ||||
-rw-r--r-- | apexd/apexd.cpp | 69 | ||||
-rw-r--r-- | apexd/apexd.h | 4 | ||||
-rw-r--r-- | apexd/apexd_vendor_apex.cpp | 35 | ||||
-rw-r--r-- | apexd/apexd_vendor_apex.h | 4 |
8 files changed, 28 insertions, 268 deletions
diff --git a/apexd/Android.bp b/apexd/Android.bp index 62366aa3..20265812 100644 --- a/apexd/Android.bp +++ b/apexd/Android.bp @@ -91,8 +91,6 @@ cc_defaults { "libtinyxml2", "libverity_tree", "libvold_binder", - "libstatslog_apex", - "libstatssocket_lazy", ], whole_static_libs: ["libcom.android.sysprop.apex"], } @@ -270,7 +268,6 @@ cc_library_static { srcs: [ "apex_file.cpp", "apex_manifest.cpp", - "apex_sha.cpp", "apex_shim.cpp", "apexd_verity.cpp", ], @@ -574,13 +571,11 @@ cc_test { "libapexd", "libfstab", "libgmock", - "libstatslog_apex", ], shared_libs: [ "libbinder", "libfs_mgr", "libutils", - "libstatssocket", ], generated_sources: ["apex-info-list-tinyxml"], test_suites: ["device-tests"], @@ -702,38 +697,3 @@ xsd_config { tinyxml: true, root_elements: ["apex-info-list"], } - -cc_library_static { - name: "libstatslog_apex", - generated_sources: ["statslog_apex.cpp"], - generated_headers: ["statslog_apex.h"], - cflags: [ - "-Wall", - "-Werror", - ], - export_generated_headers: ["statslog_apex.h"], - static_libs: [ - "libcutils", - "liblog", - "libstatssocket_lazy", - "libutils", - ], -} - -genrule { - name: "statslog_apex.h", - tools: ["stats-log-api-gen"], - cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_apex.h --module apex --namespace stats,apex", - out: [ - "statslog_apex.h", - ], -} - -genrule { - name: "statslog_apex.cpp", - tools: ["stats-log-api-gen"], - cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_apex.cpp --module apex --namespace stats,apex --importHeader statslog_apex.h", - out: [ - "statslog_apex.cpp", - ], -} diff --git a/apexd/apex_sha.cpp b/apexd/apex_sha.cpp deleted file mode 100644 index 699126d5..00000000 --- a/apexd/apex_sha.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "apex_sha.h" - -#include <android-base/logging.h> -#include <openssl/sha.h> - -#include <fstream> -#include <sstream> - -static constexpr const int kBufSize = 1024; - -using android::base::Error; -using android::base::Result; - -namespace android { -namespace apex { - -Result<std::string> CalculateSha512(const std::string& path) { - LOG(DEBUG) << "Calculating SHA512 of " << path; - SHA512_CTX ctx; - SHA512_Init(&ctx); - std::ifstream apex(path, std::ios::binary); - if (apex.bad()) { - return Error() << "Failed to open " << path; - } - char buf[kBufSize]; - while (!apex.eof()) { - apex.read(buf, kBufSize); - if (apex.bad()) { - return Error() << "Failed to read " << path; - } - int bytes_read = apex.gcount(); - SHA512_Update(&ctx, buf, bytes_read); - } - uint8_t hash[SHA512_DIGEST_LENGTH]; - SHA512_Final(hash, &ctx); - std::stringstream ss; - ss << std::hex; - for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) { - ss << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]); - } - return ss.str(); -} - -Result<std::string> CalculateSha256(const std::string& path) { - LOG(DEBUG) << "Calculating SHA256 of " << path; - SHA256_CTX ctx; - SHA256_Init(&ctx); - std::ifstream apex(path, std::ios::binary); - if (apex.bad()) { - return Error() << "Failed to open " << path; - } - char buf[kBufSize]; - while (!apex.eof()) { - apex.read(buf, kBufSize); - if (apex.bad()) { - return Error() << "Failed to read " << path; - } - int bytes_read = apex.gcount(); - SHA256_Update(&ctx, buf, bytes_read); - } - uint8_t hash[SHA256_DIGEST_LENGTH]; - SHA256_Final(hash, &ctx); - std::stringstream ss; - ss << std::hex; - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - ss << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]); - } - return ss.str(); -} - -} // namespace apex -} // namespace android diff --git a/apexd/apex_sha.h b/apexd/apex_sha.h deleted file mode 100644 index c5099166..00000000 --- a/apexd/apex_sha.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <android-base/result.h> - -namespace android { -namespace apex { - -android::base::Result<std::string> CalculateSha512(const std::string& path); -android::base::Result<std::string> CalculateSha256(const std::string& path); - -} // namespace apex -} // namespace android diff --git a/apexd/apex_shim.cpp b/apexd/apex_shim.cpp index e5030131..ffbb5568 100644 --- a/apexd/apex_shim.cpp +++ b/apexd/apex_shim.cpp @@ -21,7 +21,6 @@ #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <openssl/sha.h> - #include <filesystem> #include <fstream> #include <sstream> @@ -29,7 +28,6 @@ #include "apex_constants.h" #include "apex_file.h" -#include "apex_sha.h" #include "string_log.h" using android::base::ErrnoError; @@ -47,6 +45,7 @@ namespace { static constexpr const char* kApexCtsShimPackage = "com.android.apex.cts.shim"; static constexpr const char* kHashFilePath = "etc/hash.txt"; +static constexpr const int kBufSize = 1024; static constexpr const fs::perms kForbiddenFilePermissions = fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec; static constexpr const char* kExpectedCtsShimFiles[] = { @@ -79,6 +78,33 @@ static constexpr const char* kExpectedCtsShimFiles[] = { "priv-app/CtsShimPriv@MASTER/CtsShimPriv.apk", }; +Result<std::string> CalculateSha512(const std::string& path) { + LOG(DEBUG) << "Calculating SHA512 of " << path; + SHA512_CTX ctx; + SHA512_Init(&ctx); + std::ifstream apex(path, std::ios::binary); + if (apex.bad()) { + return Error() << "Failed to open " << path; + } + char buf[kBufSize]; + while (!apex.eof()) { + apex.read(buf, kBufSize); + if (apex.bad()) { + return Error() << "Failed to read " << path; + } + int bytes_read = apex.gcount(); + SHA512_Update(&ctx, buf, bytes_read); + } + uint8_t hash[SHA512_DIGEST_LENGTH]; + SHA512_Final(hash, &ctx); + std::stringstream ss; + ss << std::hex; + for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) { + ss << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]); + } + return ss.str(); +} + Result<std::vector<std::string>> GetAllowedHashes(const std::string& path) { using android::base::ReadFileToString; using android::base::StringPrintf; diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp index 4c169fe7..d22cebc5 100644 --- a/apexd/apexd.cpp +++ b/apexd/apexd.cpp @@ -76,7 +76,6 @@ #include "apex_file.h" #include "apex_file_repository.h" #include "apex_manifest.h" -#include "apex_sha.h" #include "apex_shim.h" #include "apexd_checkpoint.h" #include "apexd_lifecycle.h" @@ -88,7 +87,6 @@ #include "apexd_vendor_apex.h" #include "apexd_verity.h" #include "com_android_apex.h" -#include "statslog_apex.h" using android::base::boot_clock; using android::base::ConsumePrefix; @@ -716,56 +714,6 @@ Result<void> Unmount(const MountedApexData& data, bool deferred) { return {}; } -void SendApexInstallationRequestedAtom(const std::string& package_path, - const bool is_rollback, - const unsigned int install_type) { - auto apex_file = ApexFile::Open(package_path); - if (!apex_file.ok()) { - LOG(WARNING) << "Unable to send Apex Atom; Failed to open ApexFile " - << package_path << ": " << apex_file.error(); - return; - } - const std::string& module_name = apex_file->GetManifest().name(); - struct stat stat_buf; - intmax_t apex_file_size; - if (stat(package_path.c_str(), &stat_buf) == 0) { - apex_file_size = stat_buf.st_size; - } else { - PLOG(WARNING) << "Failed to stat " << package_path; - apex_file_size = 0; - } - Result<std::string> apex_file_sha256_str = CalculateSha256(package_path); - if (!apex_file_sha256_str.ok()) { - LOG(WARNING) << "Unable to get sha256 of ApexFile: " - << apex_file_sha256_str.error(); - } - const std::vector<const char*> hal_cstr_list; - int ret = stats::apex::stats_write( - stats::apex::APEX_INSTALLATION_REQUESTED, module_name.c_str(), - apex_file->GetManifest().version(), apex_file_size, - apex_file_sha256_str->c_str(), GetPreinstallPartitionEnum(*apex_file), - install_type, is_rollback, - apex_file->GetManifest().providesharedapexlibs(), hal_cstr_list); - if (ret < 0) { - LOG(WARNING) << "Failed to report apex_installation_requested stats"; - } -} - -void SendApexInstallationEndedAtom(const std::string apex_package_path, - int install_result) { - Result<std::string> apex_file_sha256_str = CalculateSha256(apex_package_path); - if (!apex_file_sha256_str.ok()) { - LOG(WARNING) << "Unable to get sha256 of ApexFile: " - << apex_file_sha256_str.error(); - } - int ret = - stats::apex::stats_write(stats::apex::APEX_INSTALLATION_ENDED, - apex_file_sha256_str->c_str(), install_result); - if (ret < 0) { - LOG(WARNING) << "Failed to report apex_installation_ended stats"; - } -} - namespace { template <typename VerifyFn> @@ -3897,23 +3845,6 @@ Result<void> LoadApexFromInit(const std::string& apex_name) { Result<ApexFile> InstallPackage(const std::string& package_path, bool force) { LOG(INFO) << "Installing " << package_path; - SendApexInstallationRequestedAtom( - package_path, /* is_rollback */ false, - stats::apex::APEX_INSTALLATION_REQUESTED__INSTALLATION_TYPE__REBOOTLESS); - // TODO: Add error-enums - Result<ApexFile> ret = InstallPackageImpl(package_path, force); - SendApexInstallationEndedAtom( - package_path, - ret.ok() - ? stats::apex:: - APEX_INSTALLATION_ENDED__INSTALLATION_RESULT__INSTALL_SUCCESSFUL - : stats::apex:: - APEX_INSTALLATION_ENDED__INSTALLATION_RESULT__INSTALL_FAILURE_APEX_INSTALLATION); - return ret; -} - -Result<ApexFile> InstallPackageImpl(const std::string& package_path, - bool force) { auto temp_apex = ApexFile::Open(package_path); if (!temp_apex.ok()) { return temp_apex.error(); diff --git a/apexd/apexd.h b/apexd/apexd.h index 90489cfa..409b0e75 100644 --- a/apexd/apexd.h +++ b/apexd/apexd.h @@ -217,10 +217,6 @@ android::apex::MountedApexDatabase& GetApexDatabaseForTesting(); // Performs a non-staged install of an APEX specified by |package_path|. // TODO(ioffe): add more documentation. -android::base::Result<ApexFile> InstallPackageImpl( - const std::string& package_path, bool force); -// Wrapper of InstallPackageImpl, which sends statsd atoms about the start and -// result android::base::Result<ApexFile> InstallPackage(const std::string& package_path, bool force); diff --git a/apexd/apexd_vendor_apex.cpp b/apexd/apexd_vendor_apex.cpp index 00dde33d..68a439ff 100644 --- a/apexd/apexd_vendor_apex.cpp +++ b/apexd/apexd_vendor_apex.cpp @@ -23,7 +23,6 @@ #include "apex_file_repository.h" #include "apexd_private.h" -#include "statslog_apex.h" using android::base::Error; using android::base::StartsWith; @@ -88,39 +87,5 @@ base::Result<void> CheckVendorApexUpdate(const ApexFile& apex_file, return {}; } -// GetPreinstallPartitionEnum returns the enumeration value of the preinstall- -// partition of the passed apex_file -int GetPreinstallPartitionEnum(const ApexFile& apex_file) { - const auto& instance = ApexFileRepository::GetInstance(); - // We must test if this apex has a pre-installed version before calling - // GetPreInstalledApex() - throws an exception if apex doesn't have one - if (!instance.IsPreInstalledApex(apex_file)) { - return stats::apex:: - APEX_INSTALLATION_REQUESTED__APEX_PREINSTALL_PARTITION__PARTITION_OTHER; - } - const auto& preinstalled = - instance.GetPreInstalledApex(apex_file.GetManifest().name()); - const auto& preinstalled_path = preinstalled.get().GetPath(); - if (StartsWith(preinstalled_path, "/vendor/") || - StartsWith(preinstalled_path, "/system/vendor/")) { - return stats::apex:: - APEX_INSTALLATION_REQUESTED__APEX_PREINSTALL_PARTITION__PARTITION_VENDOR; - } - if (StartsWith(preinstalled_path, "/system_ext/")) { - return stats::apex:: - APEX_INSTALLATION_REQUESTED__APEX_PREINSTALL_PARTITION__PARTITION_SYSTEM_EXT; - } - if (StartsWith(preinstalled_path, "/system/")) { - return stats::apex:: - APEX_INSTALLATION_REQUESTED__APEX_PREINSTALL_PARTITION__PARTITION_SYSTEM; - } - if (StartsWith(preinstalled_path, "/product/")) { - return stats::apex:: - APEX_INSTALLATION_REQUESTED__APEX_PREINSTALL_PARTITION__PARTITION_PRODUCT; - } - return stats::apex:: - APEX_INSTALLATION_REQUESTED__APEX_PREINSTALL_PARTITION__PARTITION_OTHER; -} - } // namespace apex } // namespace android diff --git a/apexd/apexd_vendor_apex.h b/apexd/apexd_vendor_apex.h index 5b0d912c..4901b02c 100644 --- a/apexd/apexd_vendor_apex.h +++ b/apexd/apexd_vendor_apex.h @@ -36,10 +36,6 @@ bool IsVendorApex(const ApexFile& apex_file); Result<void> CheckVendorApexUpdate(const ApexFile& apex_file, const std::string& apex_mount_point); -// GetPreinstallPartitionEnum returns an enumeration value of the -// preinstall partition of the passed apex_file -int GetPreinstallPartitionEnum(const ApexFile& apex_file); - } // namespace apex } // namespace android |