aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-04-18 23:35:12 -0500
committerTao Bao2017-04-19 00:07:00 -0500
commitf8119fbafba0a25c93d9b2ba82b12f4668e7d9ca (patch)
treec1d4ead4deae61ac33c9a701a3e8d8a0bf6ed65a /install.cpp
parent44f61b4ce5668d90492a02e4a61e8ffe88deac04 (diff)
downloadplatform-bootable-recovery-f8119fbafba0a25c93d9b2ba82b12f4668e7d9ca.tar.gz
platform-bootable-recovery-f8119fbafba0a25c93d9b2ba82b12f4668e7d9ca.tar.xz
platform-bootable-recovery-f8119fbafba0a25c93d9b2ba82b12f4668e7d9ca.zip
Minor clean up to install.cpp.
- Move some macros / constants into functions; - Remove unneeded #include "minui/minui.h"; - Remove two dead constants (DEFAULT_{FILES,IMAGES}_PROGRESS_FRACTION). Test: mmma bootable/recovery Change-Id: Ib808f14b7569e06e23a8a7cc9b2d4e9aa5469de1
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp127
1 files changed, 61 insertions, 66 deletions
diff --git a/install.cpp b/install.cpp
index 4fb80999..95794ce0 100644
--- a/install.cpp
+++ b/install.cpp
@@ -48,7 +48,6 @@
48 48
49#include "common.h" 49#include "common.h"
50#include "error_code.h" 50#include "error_code.h"
51#include "minui/minui.h"
52#include "otautil/SysUtil.h" 51#include "otautil/SysUtil.h"
53#include "otautil/ThermalUtil.h" 52#include "otautil/ThermalUtil.h"
54#include "roots.h" 53#include "roots.h"
@@ -57,15 +56,11 @@
57 56
58using namespace std::chrono_literals; 57using namespace std::chrono_literals;
59 58
60#define PUBLIC_KEYS_FILE "/res/keys"
61static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata"; 59static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
62static constexpr const char* UNCRYPT_STATUS = "/cache/recovery/uncrypt_status";
63 60
64// Default allocation of progress bar segments to operations 61// Default allocation of progress bar segments to operations
65static constexpr int VERIFICATION_PROGRESS_TIME = 60; 62static constexpr int VERIFICATION_PROGRESS_TIME = 60;
66static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25; 63static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
67static constexpr float DEFAULT_FILES_PROGRESS_FRACTION = 0.4;
68static constexpr float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1;
69 64
70static std::condition_variable finish_log_temperature; 65static std::condition_variable finish_log_temperature;
71 66
@@ -621,80 +616,80 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
621 return result; 616 return result;
622} 617}
623 618
624int 619int install_package(const char* path, bool* wipe_cache, const char* install_file, bool needs_mount,
625install_package(const char* path, bool* wipe_cache, const char* install_file, 620 int retry_count) {
626 bool needs_mount, int retry_count) 621 modified_flash = true;
627{ 622 auto start = std::chrono::system_clock::now();
628 modified_flash = true; 623
629 auto start = std::chrono::system_clock::now(); 624 int start_temperature = GetMaxValueFromThermalZone();
625 int max_temperature = start_temperature;
626
627 int result;
628 std::vector<std::string> log_buffer;
629 if (setup_install_mounts() != 0) {
630 LOG(ERROR) << "failed to set up expected mounts for install; aborting";
631 result = INSTALL_ERROR;
632 } else {
633 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count,
634 &max_temperature);
635 }
630 636
631 int start_temperature = GetMaxValueFromThermalZone(); 637 // Measure the time spent to apply OTA update in seconds.
632 int max_temperature = start_temperature; 638 std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
639 int time_total = static_cast<int>(duration.count());
633 640
634 int result; 641 bool has_cache = volume_for_path("/cache") != nullptr;
635 std::vector<std::string> log_buffer; 642 // Skip logging the uncrypt_status on devices without /cache.
636 if (setup_install_mounts() != 0) { 643 if (has_cache) {
637 LOG(ERROR) << "failed to set up expected mounts for install; aborting"; 644 static constexpr const char* UNCRYPT_STATUS = "/cache/recovery/uncrypt_status";
638 result = INSTALL_ERROR; 645 if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
646 LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS;
639 } else { 647 } else {
640 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count, 648 std::string uncrypt_status;
641 &max_temperature); 649 if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
642 } 650 PLOG(WARNING) << "failed to read uncrypt status";
643 651 } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_")) {
644 // Measure the time spent to apply OTA update in seconds. 652 LOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
645 std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
646 int time_total = static_cast<int>(duration.count());
647
648 bool has_cache = volume_for_path("/cache") != nullptr;
649 // Skip logging the uncrypt_status on devices without /cache.
650 if (has_cache) {
651 if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
652 LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS;
653 } else { 653 } else {
654 std::string uncrypt_status; 654 log_buffer.push_back(android::base::Trim(uncrypt_status));
655 if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
656 PLOG(WARNING) << "failed to read uncrypt status";
657 } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_")) {
658 LOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
659 } else {
660 log_buffer.push_back(android::base::Trim(uncrypt_status));
661 }
662 } 655 }
663 } 656 }
657 }
664 658
665 // The first two lines need to be the package name and install result. 659 // The first two lines need to be the package name and install result.
666 std::vector<std::string> log_header = { 660 std::vector<std::string> log_header = {
667 path, 661 path,
668 result == INSTALL_SUCCESS ? "1" : "0", 662 result == INSTALL_SUCCESS ? "1" : "0",
669 "time_total: " + std::to_string(time_total), 663 "time_total: " + std::to_string(time_total),
670 "retry: " + std::to_string(retry_count), 664 "retry: " + std::to_string(retry_count),
671 }; 665 };
672
673 int end_temperature = GetMaxValueFromThermalZone();
674 max_temperature = std::max(end_temperature, max_temperature);
675 if (start_temperature > 0) {
676 log_buffer.push_back("temperature_start: " + std::to_string(start_temperature));
677 }
678 if (end_temperature > 0) {
679 log_buffer.push_back("temperature_end: " + std::to_string(end_temperature));
680 }
681 if (max_temperature > 0) {
682 log_buffer.push_back("temperature_max: " + std::to_string(max_temperature));
683 }
684 666
685 std::string log_content = android::base::Join(log_header, "\n") + "\n" + 667 int end_temperature = GetMaxValueFromThermalZone();
686 android::base::Join(log_buffer, "\n") + "\n"; 668 max_temperature = std::max(end_temperature, max_temperature);
687 if (!android::base::WriteStringToFile(log_content, install_file)) { 669 if (start_temperature > 0) {
688 PLOG(ERROR) << "failed to write " << install_file; 670 log_buffer.push_back("temperature_start: " + std::to_string(start_temperature));
689 } 671 }
672 if (end_temperature > 0) {
673 log_buffer.push_back("temperature_end: " + std::to_string(end_temperature));
674 }
675 if (max_temperature > 0) {
676 log_buffer.push_back("temperature_max: " + std::to_string(max_temperature));
677 }
690 678
691 // Write a copy into last_log. 679 std::string log_content =
692 LOG(INFO) << log_content; 680 android::base::Join(log_header, "\n") + "\n" + android::base::Join(log_buffer, "\n") + "\n";
681 if (!android::base::WriteStringToFile(log_content, install_file)) {
682 PLOG(ERROR) << "failed to write " << install_file;
683 }
693 684
694 return result; 685 // Write a copy into last_log.
686 LOG(INFO) << log_content;
687
688 return result;
695} 689}
696 690
697bool verify_package(const unsigned char* package_data, size_t package_size) { 691bool verify_package(const unsigned char* package_data, size_t package_size) {
692 static constexpr const char* PUBLIC_KEYS_FILE = "/res/keys";
698 std::vector<Certificate> loadedKeys; 693 std::vector<Certificate> loadedKeys;
699 if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { 694 if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) {
700 LOG(ERROR) << "Failed to load keys"; 695 LOG(ERROR) << "Failed to load keys";