aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-03-07 02:56:27 -0600
committerTao Bao2017-03-07 02:57:08 -0600
commit08fc6beef895e7bca34428cdce5c12cdf9938b65 (patch)
treee22faf25ed90cec5af7af2f3c375400ba922291e /recovery.cpp
parenta2e7a07031d72e617ddf082897d76f8b83fc52e3 (diff)
downloadplatform-bootable-recovery-08fc6beef895e7bca34428cdce5c12cdf9938b65.tar.gz
platform-bootable-recovery-08fc6beef895e7bca34428cdce5c12cdf9938b65.tar.xz
platform-bootable-recovery-08fc6beef895e7bca34428cdce5c12cdf9938b65.zip
recovery: Minor clean up to choose_recovery_file().
Test: 'View recovery logs' on bullhead and sailfish. Change-Id: I53272b121e3e55e6fe4c77b71e3c2e819e72cb64
Diffstat (limited to 'recovery.cpp')
-rw-r--r--recovery.cpp86
1 files changed, 35 insertions, 51 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 5c60ce65..223ca94d 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -922,67 +922,51 @@ static bool wipe_ab_device(size_t wipe_package_size) {
922} 922}
923 923
924static void choose_recovery_file(Device* device) { 924static void choose_recovery_file(Device* device) {
925 // "Back" + KEEP_LOG_COUNT * 2 + terminating nullptr entry 925 std::vector<std::string> entries;
926 char* entries[1 + KEEP_LOG_COUNT * 2 + 1]; 926 if (has_cache) {
927 memset(entries, 0, sizeof(entries)); 927 for (int i = 0; i < KEEP_LOG_COUNT; i++) {
928 auto add_to_entries = [&](const char* filename) {
929 std::string log_file(filename);
930 if (i > 0) {
931 log_file += "." + std::to_string(i);
932 }
928 933
929 unsigned int n = 0; 934 if (ensure_path_mounted(log_file.c_str()) == 0 && access(log_file.c_str(), R_OK) == 0) {
935 entries.push_back(std::move(log_file));
936 }
937 };
930 938
931 if (has_cache) { 939 // Add LAST_LOG_FILE + LAST_LOG_FILE.x
932 // Add LAST_LOG_FILE + LAST_LOG_FILE.x 940 add_to_entries(LAST_LOG_FILE);
933 // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x
934 for (int i = 0; i < KEEP_LOG_COUNT; i++) {
935 char* log_file;
936 int ret;
937 ret = (i == 0) ? asprintf(&log_file, "%s", LAST_LOG_FILE) :
938 asprintf(&log_file, "%s.%d", LAST_LOG_FILE, i);
939 if (ret == -1) {
940 // memory allocation failure - return early. Should never happen.
941 return;
942 }
943 if ((ensure_path_mounted(log_file) != 0) || (access(log_file, R_OK) == -1)) {
944 free(log_file);
945 } else {
946 entries[n++] = log_file;
947 }
948 941
949 char* kmsg_file; 942 // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x
950 ret = (i == 0) ? asprintf(&kmsg_file, "%s", LAST_KMSG_FILE) : 943 add_to_entries(LAST_KMSG_FILE);
951 asprintf(&kmsg_file, "%s.%d", LAST_KMSG_FILE, i); 944 }
952 if (ret == -1) { 945 } else {
953 // memory allocation failure - return early. Should never happen. 946 // If cache partition is not found, view /tmp/recovery.log instead.
954 return; 947 if (access(TEMPORARY_LOG_FILE, R_OK) == -1) {
955 } 948 return;
956 if ((ensure_path_mounted(kmsg_file) != 0) || (access(kmsg_file, R_OK) == -1)) {
957 free(kmsg_file);
958 } else {
959 entries[n++] = kmsg_file;
960 }
961 }
962 } else { 949 } else {
963 // If cache partition is not found, view /tmp/recovery.log instead. 950 entries.push_back(TEMPORARY_LOG_FILE);
964 if (access(TEMPORARY_LOG_FILE, R_OK) == -1) {
965 return;
966 } else{
967 entries[n++] = strdup(TEMPORARY_LOG_FILE);
968 }
969 } 951 }
952 }
970 953
971 entries[n++] = strdup("Back"); 954 entries.push_back("Back");
972 955
973 const char* headers[] = { "Select file to view", nullptr }; 956 std::vector<const char*> menu_entries(entries.size());
957 std::transform(entries.cbegin(), entries.cend(), menu_entries.begin(),
958 [](const std::string& entry) { return entry.c_str(); });
959 menu_entries.push_back(nullptr);
974 960
975 int chosen_item = 0; 961 const char* headers[] = { "Select file to view", nullptr };
976 while (true) {
977 chosen_item = get_menu_selection(headers, entries, 1, chosen_item, device);
978 if (strcmp(entries[chosen_item], "Back") == 0) break;
979 962
980 ui->ShowFile(entries[chosen_item]); 963 int chosen_item = 0;
981 } 964 while (true) {
965 chosen_item = get_menu_selection(headers, menu_entries.data(), 1, chosen_item, device);
966 if (entries[chosen_item] == "Back") break;
982 967
983 for (size_t i = 0; i < (sizeof(entries) / sizeof(*entries)); i++) { 968 ui->ShowFile(entries[chosen_item].c_str());
984 free(entries[i]); 969 }
985 }
986} 970}
987 971
988static void run_graphics_test(Device* device) { 972static void run_graphics_test(Device* device) {