From adc99efd1cfd94283c6a1c5c9e9a4ce4af2c5daf Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 29 Apr 2019 23:48:02 -0700 Subject: install: Install functions return InstallResult. Test: `atest recovery_unit_test recovery_component_test` Test: Sideload a package on taimen. Change-Id: I2d42f55a89931ee495ea5c5d9e6b5ee1058e8e52 --- install/install.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'install/install.cpp') diff --git a/install/install.cpp b/install/install.cpp index 3f4df13e1..5d514fa23 100644 --- a/install/install.cpp +++ b/install/install.cpp @@ -324,9 +324,9 @@ static void log_max_temperature(int* max_temperature, const std::atomic& l } // If the package contains an update binary, extract it and run it. -static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache, - std::vector* log_buffer, int retry_count, - int* max_temperature, RecoveryUI* ui) { +static InstallResult TryUpdateBinary(const std::string& package, ZipArchiveHandle zip, + bool* wipe_cache, std::vector* log_buffer, + int retry_count, int* max_temperature, RecoveryUI* ui) { std::map metadata; if (!ReadMetadataFromPackage(zip, &metadata)) { LOG(ERROR) << "Failed to parse metadata in the zip file"; @@ -569,9 +569,10 @@ bool verify_package_compatibility(ZipArchiveHandle package_zip) { return false; } -static int really_install_package(const std::string& path, bool* wipe_cache, bool needs_mount, - std::vector* log_buffer, int retry_count, - int* max_temperature, RecoveryUI* ui) { +static InstallResult VerifyAndInstallPackage(const std::string& path, bool* wipe_cache, + bool needs_mount, std::vector* log_buffer, + int retry_count, int* max_temperature, + RecoveryUI* ui) { ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); ui->Print("Finding update package...\n"); // Give verification half the progress bar... @@ -622,16 +623,16 @@ static int really_install_package(const std::string& path, bool* wipe_cache, boo ui->Print("Retry attempt: %d\n", retry_count); } ui->SetEnableReboot(false); - int result = - try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature, ui); + auto result = + TryUpdateBinary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature, ui); ui->SetEnableReboot(true); ui->Print("\n"); return result; } -int install_package(const std::string& path, bool should_wipe_cache, bool needs_mount, - int retry_count, RecoveryUI* ui) { +InstallResult InstallPackage(const std::string& path, bool should_wipe_cache, bool needs_mount, + int retry_count, RecoveryUI* ui) { CHECK(!path.empty()); auto start = std::chrono::system_clock::now(); @@ -639,15 +640,15 @@ int install_package(const std::string& path, bool should_wipe_cache, bool needs_ int start_temperature = GetMaxValueFromThermalZone(); int max_temperature = start_temperature; - int result; + InstallResult result; std::vector log_buffer; if (setup_install_mounts() != 0) { LOG(ERROR) << "failed to set up expected mounts for install; aborting"; result = INSTALL_ERROR; } else { bool updater_wipe_cache = false; - result = really_install_package(path, &updater_wipe_cache, needs_mount, &log_buffer, - retry_count, &max_temperature, ui); + result = VerifyAndInstallPackage(path, &updater_wipe_cache, needs_mount, &log_buffer, + retry_count, &max_temperature, ui); should_wipe_cache = should_wipe_cache || updater_wipe_cache; } -- cgit v1.2.3