From badaac45fee6e39dd74001ea3b2aa954afb37999 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 26 Sep 2016 11:39:14 -0700 Subject: Duplicate the last_install content into last_log. Currently we save the OTA metrics in last_install, which keeps the data for the _last_ install only. This CL logs the same content into last_log so that we keep the metrics for every install. Bug: 31607469 Test: Apply an update (via OTA and sideload) and check last_log and last_install. Change-Id: Id8f174d79534fddc9f06d72a4e69b2b1d8ab186c (cherry picked from commit f4885adc189f246ac3c651aa5cb2e74a240f3f1e) --- recovery.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'recovery.cpp') diff --git a/recovery.cpp b/recovery.cpp index d3f9c47ae..a076f1e37 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1434,15 +1434,18 @@ static bool bootreason_in_blacklist() { } static void log_failure_code(ErrorCode code, const char *update_package) { - FILE* install_log = fopen_path(TEMPORARY_INSTALL_FILE, "w"); - if (install_log != nullptr) { - fprintf(install_log, "%s\n", update_package); - fprintf(install_log, "0\n"); - fprintf(install_log, "error: %d\n", code); - fclose(install_log); - } else { - PLOG(ERROR) << "failed to open last_install"; + std::vector log_buffer = { + update_package, + "0", // install result + "error: " + std::to_string(code), + }; + std::string log_content = android::base::Join(log_buffer, "\n"); + if (!android::base::WriteStringToFile(log_content, TEMPORARY_INSTALL_FILE)) { + PLOG(ERROR) << "failed to write " << TEMPORARY_INSTALL_FILE; } + + // Also write the info into last_log. + LOG(INFO) << log_content; } static ssize_t logbasename( -- cgit v1.2.3