From cf60a44bd497599363c0efcab23eb6be376c741f Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 18 Jun 2018 14:56:20 -0700 Subject: Drop the dependency on AB_OTA_UPDATER flag. This shortens the gap between A/B and non-A/B builds, by replacing the dependency on build-time flag with runtime detection instead. It also allows building and testing both paths regardless of the target OTA type. The size increase to /sbin/recovery looks negligible (< 0.01%). - marlin: increased from 2084928 to 2085024; - angler: increased from 2084776 to 2084896. Test: Run recovery_component_test on angler and marlin. Test: Sideload an A/B OTA package on marlin. Test: Sideload a non-A/B OTA package on angler. Change-Id: I1d927d1ede9713fb42f73b4fe324aa5705ee6f99 --- install.cpp | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'install.cpp') diff --git a/install.cpp b/install.cpp index a4c6986a6..800847fdb 100644 --- a/install.cpp +++ b/install.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -124,11 +125,9 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector* cmd) { CHECK(cmd != nullptr); int ret = check_newer_ab_build(zip); @@ -250,7 +248,7 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip, } long payload_offset = payload_entry.offset; *cmd = { - binary_path, + "/sbin/update_engine_sideload", "--payload=file://" + package, android::base::StringPrintf("--offset=%ld", payload_offset), "--headers=" + std::string(payload_properties.begin(), payload_properties.end()), @@ -259,14 +257,11 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip, return 0; } -#else // !AB_OTA_UPDATER - -int update_binary_command(const std::string& package, ZipArchiveHandle zip, - const std::string& binary_path, int retry_count, int status_fd, - std::vector* cmd) { +int SetUpNonAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int retry_count, + int status_fd, std::vector* cmd) { CHECK(cmd != nullptr); - // On traditional updates we extract the update binary from the package. + // In non-A/B updates we extract the update binary from the package. static constexpr const char* UPDATE_BINARY_NAME = "META-INF/com/google/android/update-binary"; ZipString binary_name(UPDATE_BINARY_NAME); ZipEntry binary_entry; @@ -275,15 +270,16 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip, return INSTALL_CORRUPT; } + const std::string binary_path = Paths::Get().temporary_update_binary(); unlink(binary_path.c_str()); - int fd = open(binary_path.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0755); + android::base::unique_fd fd( + open(binary_path.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0755)); if (fd == -1) { PLOG(ERROR) << "Failed to create " << binary_path; return INSTALL_ERROR; } int32_t error = ExtractEntryToFile(zip, &binary_entry, fd); - close(fd); if (error != 0) { LOG(ERROR) << "Failed to extract " << UPDATE_BINARY_NAME << ": " << ErrorCodeString(error); return INSTALL_ERROR; @@ -300,7 +296,6 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip, } return 0; } -#endif // !AB_OTA_UPDATER static void log_max_temperature(int* max_temperature, const std::atomic& logger_finished) { CHECK(max_temperature != nullptr); @@ -321,14 +316,10 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b int pipefd[2]; pipe(pipefd); + bool is_ab = android::base::GetBoolProperty("ro.build.ab_update", false); std::vector args; -#ifdef AB_OTA_UPDATER - int ret = update_binary_command(package, zip, "/sbin/update_engine_sideload", retry_count, - pipefd[1], &args); -#else - int ret = update_binary_command(package, zip, "/tmp/update-binary", retry_count, pipefd[1], - &args); -#endif + int ret = is_ab ? SetUpAbUpdateCommands(package, zip, pipefd[1], &args) + : SetUpNonAbUpdateCommands(package, zip, retry_count, pipefd[1], &args); if (ret) { close(pipefd[0]); close(pipefd[1]); -- cgit v1.2.3