diff options
author | Tao Bao <tbao@google.com> | 2017-03-07 20:45:39 +0100 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-03-07 20:45:40 +0100 |
commit | 73d21d1c1c9cded236b61725e49caf8819ba8bb0 (patch) | |
tree | e22faf25ed90cec5af7af2f3c375400ba922291e /recovery.cpp | |
parent | Merge "Refractor the code for imgdiff" (diff) | |
parent | recovery: Minor clean up to choose_recovery_file(). (diff) | |
download | android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.tar android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.tar.gz android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.tar.bz2 android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.tar.lz android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.tar.xz android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.tar.zst android_bootable_recovery-73d21d1c1c9cded236b61725e49caf8819ba8bb0.zip |
Diffstat (limited to 'recovery.cpp')
-rw-r--r-- | recovery.cpp | 86 |
1 files changed, 35 insertions, 51 deletions
diff --git a/recovery.cpp b/recovery.cpp index 5c60ce655..223ca94d0 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -922,67 +922,51 @@ static bool wipe_ab_device(size_t wipe_package_size) { } static void choose_recovery_file(Device* device) { - // "Back" + KEEP_LOG_COUNT * 2 + terminating nullptr entry - char* entries[1 + KEEP_LOG_COUNT * 2 + 1]; - memset(entries, 0, sizeof(entries)); + std::vector<std::string> entries; + if (has_cache) { + for (int i = 0; i < KEEP_LOG_COUNT; i++) { + auto add_to_entries = [&](const char* filename) { + std::string log_file(filename); + if (i > 0) { + log_file += "." + std::to_string(i); + } - unsigned int n = 0; + if (ensure_path_mounted(log_file.c_str()) == 0 && access(log_file.c_str(), R_OK) == 0) { + entries.push_back(std::move(log_file)); + } + }; - if (has_cache) { - // Add LAST_LOG_FILE + LAST_LOG_FILE.x - // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x - for (int i = 0; i < KEEP_LOG_COUNT; i++) { - char* log_file; - int ret; - ret = (i == 0) ? asprintf(&log_file, "%s", LAST_LOG_FILE) : - asprintf(&log_file, "%s.%d", LAST_LOG_FILE, i); - if (ret == -1) { - // memory allocation failure - return early. Should never happen. - return; - } - if ((ensure_path_mounted(log_file) != 0) || (access(log_file, R_OK) == -1)) { - free(log_file); - } else { - entries[n++] = log_file; - } + // Add LAST_LOG_FILE + LAST_LOG_FILE.x + add_to_entries(LAST_LOG_FILE); - char* kmsg_file; - ret = (i == 0) ? asprintf(&kmsg_file, "%s", LAST_KMSG_FILE) : - asprintf(&kmsg_file, "%s.%d", LAST_KMSG_FILE, i); - if (ret == -1) { - // memory allocation failure - return early. Should never happen. - return; - } - if ((ensure_path_mounted(kmsg_file) != 0) || (access(kmsg_file, R_OK) == -1)) { - free(kmsg_file); - } else { - entries[n++] = kmsg_file; - } - } + // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x + add_to_entries(LAST_KMSG_FILE); + } + } else { + // If cache partition is not found, view /tmp/recovery.log instead. + if (access(TEMPORARY_LOG_FILE, R_OK) == -1) { + return; } else { - // If cache partition is not found, view /tmp/recovery.log instead. - if (access(TEMPORARY_LOG_FILE, R_OK) == -1) { - return; - } else{ - entries[n++] = strdup(TEMPORARY_LOG_FILE); - } + entries.push_back(TEMPORARY_LOG_FILE); } + } - entries[n++] = strdup("Back"); + entries.push_back("Back"); - const char* headers[] = { "Select file to view", nullptr }; + std::vector<const char*> menu_entries(entries.size()); + std::transform(entries.cbegin(), entries.cend(), menu_entries.begin(), + [](const std::string& entry) { return entry.c_str(); }); + menu_entries.push_back(nullptr); - int chosen_item = 0; - while (true) { - chosen_item = get_menu_selection(headers, entries, 1, chosen_item, device); - if (strcmp(entries[chosen_item], "Back") == 0) break; + const char* headers[] = { "Select file to view", nullptr }; - ui->ShowFile(entries[chosen_item]); - } + int chosen_item = 0; + while (true) { + chosen_item = get_menu_selection(headers, menu_entries.data(), 1, chosen_item, device); + if (entries[chosen_item] == "Back") break; - for (size_t i = 0; i < (sizeof(entries) / sizeof(*entries)); i++) { - free(entries[i]); - } + ui->ShowFile(entries[chosen_item].c_str()); + } } static void run_graphics_test(Device* device) { |