summaryrefslogtreecommitdiffstats
path: root/install.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--install.cpp215
1 files changed, 103 insertions, 112 deletions
diff --git a/install.cpp b/install.cpp
index ffeba2e18..e945d13ab 100644
--- a/install.cpp
+++ b/install.cpp
@@ -49,7 +49,6 @@
#include "common.h"
#include "error_code.h"
-#include "minui/minui.h"
#include "otautil/SysUtil.h"
#include "otautil/ThermalUtil.h"
#include "roots.h"
@@ -58,15 +57,9 @@
using namespace std::chrono_literals;
-#define PUBLIC_KEYS_FILE "/res/keys"
-static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
-static constexpr const char* UNCRYPT_STATUS = "/cache/recovery/uncrypt_status";
-
// Default allocation of progress bar segments to operations
static constexpr int VERIFICATION_PROGRESS_TIME = 60;
static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
-static constexpr float DEFAULT_FILES_PROGRESS_FRACTION = 0.4;
-static constexpr float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1;
static std::condition_variable finish_log_temperature;
@@ -85,53 +78,51 @@ static int parse_build_number(const std::string& str) {
return -1;
}
-bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) {
- ZipString metadata_path(METADATA_PATH);
- ZipEntry meta_entry;
- if (meta_data == nullptr) {
- LOG(ERROR) << "string* meta_data can't be nullptr";
- return false;
- }
- if (FindEntry(zip, metadata_path, &meta_entry) != 0) {
- LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package";
- return false;
- }
+bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata) {
+ CHECK(metadata != nullptr);
- meta_data->resize(meta_entry.uncompressed_length, '\0');
- if (ExtractToMemory(zip, &meta_entry, reinterpret_cast<uint8_t*>(&(*meta_data)[0]),
- meta_entry.uncompressed_length) != 0) {
- LOG(ERROR) << "Failed to read metadata in update package";
- return false;
- }
- return true;
+ static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
+ ZipString path(METADATA_PATH);
+ ZipEntry entry;
+ if (FindEntry(zip, path, &entry) != 0) {
+ LOG(ERROR) << "Failed to find " << METADATA_PATH;
+ return false;
+ }
+
+ uint32_t length = entry.uncompressed_length;
+ metadata->resize(length, '\0');
+ int32_t err = ExtractToMemory(zip, &entry, reinterpret_cast<uint8_t*>(&(*metadata)[0]), length);
+ if (err != 0) {
+ LOG(ERROR) << "Failed to extract " << METADATA_PATH << ": " << ErrorCodeString(err);
+ return false;
+ }
+ return true;
}
// Read the build.version.incremental of src/tgt from the metadata and log it to last_install.
static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) {
- std::string meta_data;
- if (!read_metadata_from_package(zip, &meta_data)) {
- return;
- }
- // Examples of the pre-build and post-build strings in metadata:
- // pre-build-incremental=2943039
- // post-build-incremental=2951741
- std::vector<std::string> lines = android::base::Split(meta_data, "\n");
- for (const std::string& line : lines) {
- std::string str = android::base::Trim(line);
- if (android::base::StartsWith(str, "pre-build-incremental")){
- int source_build = parse_build_number(str);
- if (source_build != -1) {
- log_buffer.push_back(android::base::StringPrintf("source_build: %d",
- source_build));
- }
- } else if (android::base::StartsWith(str, "post-build-incremental")) {
- int target_build = parse_build_number(str);
- if (target_build != -1) {
- log_buffer.push_back(android::base::StringPrintf("target_build: %d",
- target_build));
- }
- }
+ std::string metadata;
+ if (!read_metadata_from_package(zip, &metadata)) {
+ return;
+ }
+ // Examples of the pre-build and post-build strings in metadata:
+ // pre-build-incremental=2943039
+ // post-build-incremental=2951741
+ std::vector<std::string> lines = android::base::Split(metadata, "\n");
+ for (const std::string& line : lines) {
+ std::string str = android::base::Trim(line);
+ if (android::base::StartsWith(str, "pre-build-incremental")) {
+ int source_build = parse_build_number(str);
+ if (source_build != -1) {
+ log_buffer.push_back(android::base::StringPrintf("source_build: %d", source_build));
+ }
+ } else if (android::base::StartsWith(str, "post-build-incremental")) {
+ int target_build = parse_build_number(str);
+ if (target_build != -1) {
+ log_buffer.push_back(android::base::StringPrintf("target_build: %d", target_build));
+ }
}
+ }
}
// Extract the update binary from the open zip archive |zip| located at |path| and store into |cmd|
@@ -220,7 +211,7 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {
return 0;
}
-int update_binary_command(const std::string& path, ZipArchiveHandle zip, int retry_count,
+int update_binary_command(const std::string& path, ZipArchiveHandle zip, int /* retry_count */,
int status_fd, std::vector<std::string>* cmd) {
CHECK(cmd != nullptr);
int ret = check_newer_ab_build(zip);
@@ -626,80 +617,80 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
return result;
}
-int
-install_package(const char* path, bool* wipe_cache, const char* install_file,
- bool needs_mount, int retry_count)
-{
- modified_flash = true;
- auto start = std::chrono::system_clock::now();
-
- int start_temperature = GetMaxValueFromThermalZone();
- int max_temperature = start_temperature;
-
- int result;
- std::vector<std::string> log_buffer;
- if (setup_install_mounts() != 0) {
- LOG(ERROR) << "failed to set up expected mounts for install; aborting";
- result = INSTALL_ERROR;
+int install_package(const char* path, bool* wipe_cache, const char* install_file, bool needs_mount,
+ int retry_count) {
+ modified_flash = true;
+ auto start = std::chrono::system_clock::now();
+
+ int start_temperature = GetMaxValueFromThermalZone();
+ int max_temperature = start_temperature;
+
+ int result;
+ std::vector<std::string> log_buffer;
+ if (setup_install_mounts() != 0) {
+ LOG(ERROR) << "failed to set up expected mounts for install; aborting";
+ result = INSTALL_ERROR;
+ } else {
+ result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count,
+ &max_temperature);
+ }
+
+ // Measure the time spent to apply OTA update in seconds.
+ std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
+ int time_total = static_cast<int>(duration.count());
+
+ bool has_cache = volume_for_path("/cache") != nullptr;
+ // Skip logging the uncrypt_status on devices without /cache.
+ if (has_cache) {
+ static constexpr const char* UNCRYPT_STATUS = "/cache/recovery/uncrypt_status";
+ if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
+ LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS;
} else {
- result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count,
- &max_temperature);
- }
-
- // Measure the time spent to apply OTA update in seconds.
- std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
- int time_total = static_cast<int>(duration.count());
-
- bool has_cache = volume_for_path("/cache") != nullptr;
- // Skip logging the uncrypt_status on devices without /cache.
- if (has_cache) {
- if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
- LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS;
+ std::string uncrypt_status;
+ if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
+ PLOG(WARNING) << "failed to read uncrypt status";
+ } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_")) {
+ LOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
} else {
- std::string uncrypt_status;
- if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
- PLOG(WARNING) << "failed to read uncrypt status";
- } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_")) {
- LOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
- } else {
- log_buffer.push_back(android::base::Trim(uncrypt_status));
- }
+ log_buffer.push_back(android::base::Trim(uncrypt_status));
}
}
+ }
- // The first two lines need to be the package name and install result.
- std::vector<std::string> log_header = {
- path,
- result == INSTALL_SUCCESS ? "1" : "0",
- "time_total: " + std::to_string(time_total),
- "retry: " + std::to_string(retry_count),
- };
-
- int end_temperature = GetMaxValueFromThermalZone();
- max_temperature = std::max(end_temperature, max_temperature);
- if (start_temperature > 0) {
- log_buffer.push_back("temperature_start: " + std::to_string(start_temperature));
- }
- if (end_temperature > 0) {
- log_buffer.push_back("temperature_end: " + std::to_string(end_temperature));
- }
- if (max_temperature > 0) {
- log_buffer.push_back("temperature_max: " + std::to_string(max_temperature));
- }
+ // The first two lines need to be the package name and install result.
+ std::vector<std::string> log_header = {
+ path,
+ result == INSTALL_SUCCESS ? "1" : "0",
+ "time_total: " + std::to_string(time_total),
+ "retry: " + std::to_string(retry_count),
+ };
- std::string log_content = android::base::Join(log_header, "\n") + "\n" +
- android::base::Join(log_buffer, "\n") + "\n";
- if (!android::base::WriteStringToFile(log_content, install_file)) {
- PLOG(ERROR) << "failed to write " << install_file;
- }
+ int end_temperature = GetMaxValueFromThermalZone();
+ max_temperature = std::max(end_temperature, max_temperature);
+ if (start_temperature > 0) {
+ log_buffer.push_back("temperature_start: " + std::to_string(start_temperature));
+ }
+ if (end_temperature > 0) {
+ log_buffer.push_back("temperature_end: " + std::to_string(end_temperature));
+ }
+ if (max_temperature > 0) {
+ log_buffer.push_back("temperature_max: " + std::to_string(max_temperature));
+ }
+
+ std::string log_content =
+ android::base::Join(log_header, "\n") + "\n" + android::base::Join(log_buffer, "\n") + "\n";
+ if (!android::base::WriteStringToFile(log_content, install_file)) {
+ PLOG(ERROR) << "failed to write " << install_file;
+ }
- // Write a copy into last_log.
- LOG(INFO) << log_content;
+ // Write a copy into last_log.
+ LOG(INFO) << log_content;
- return result;
+ return result;
}
bool verify_package(const unsigned char* package_data, size_t package_size) {
+ static constexpr const char* PUBLIC_KEYS_FILE = "/res/keys";
std::vector<Certificate> loadedKeys;
if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) {
LOG(ERROR) << "Failed to load keys";