diff options
Diffstat (limited to 'recovery.cpp')
-rw-r--r-- | recovery.cpp | 157 |
1 files changed, 81 insertions, 76 deletions
diff --git a/recovery.cpp b/recovery.cpp index 7c1d7fb0f..d028cc917 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -37,8 +37,9 @@ #include "minui/minui.h" #include "minzip/DirUtil.h" #include "roots.h" -#include "recovery_ui.h" #include "ui.h" +#include "screen_ui.h" +#include "device.h" static const struct option OPTIONS[] = { { "send_intent", required_argument, NULL, 's' }, @@ -62,6 +63,8 @@ static const char *SIDELOAD_TEMP_DIR = "/tmp/sideload"; extern UIParameters ui_parameters; // from ui.c +RecoveryUI* ui = NULL; + /* * The recovery tool communicates with the main system through /cache files. * /cache/recovery/command - INPUT - command line for tool, one arg per line @@ -291,9 +294,9 @@ finish_recovery(const char *send_intent) { static int erase_volume(const char *volume) { - ui_set_background(BACKGROUND_ICON_INSTALLING); - ui_show_indeterminate_progress(); - ui_print("Formatting %s...\n", volume); + ui->SetBackground(RecoveryUI::INSTALLING); + ui->SetProgressType(RecoveryUI::INDETERMINATE); + ui->Print("Formatting %s...\n", volume); ensure_path_unmounted(volume); @@ -398,7 +401,7 @@ copy_sideloaded_package(const char* original_path) { } static const char** -prepend_title(const char** headers) { +prepend_title(const char* const* headers) { const char* title[] = { "Android system recovery <" EXPAND(RECOVERY_API_VERSION) "e>", "", @@ -407,7 +410,7 @@ prepend_title(const char** headers) { // count the number of lines in our title, plus the // caller-provided headers. int count = 0; - const char** p; + const char* const* p; for (p = title; *p; ++p, ++count); for (p = headers; *p; ++p, ++count); @@ -422,45 +425,45 @@ prepend_title(const char** headers) { static int get_menu_selection(const char* const * headers, const char* const * items, - int menu_only, int initial_selection) { + int menu_only, int initial_selection, Device* device) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. - ui_clear_key_queue(); + ui->FlushKeys(); - ui_start_menu(headers, items, initial_selection); + ui->StartMenu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; while (chosen_item < 0) { - int key = ui_wait_key(); - int visible = ui_text_visible(); + int key = ui->WaitKey(); + int visible = ui->IsTextVisible(); if (key == -1) { // ui_wait_key() timed out - if (ui_text_ever_visible()) { + if (ui->WasTextEverVisible()) { continue; } else { LOGI("timed out waiting for key input; rebooting.\n"); - ui_end_menu(); - return ITEM_REBOOT; + ui->EndMenu(); + return 0; // XXX fixme } } - int action = device_handle_key(key, visible); + int action = device->HandleMenuKey(key, visible); if (action < 0) { switch (action) { - case HIGHLIGHT_UP: + case Device::kHighlightUp: --selected; - selected = ui_menu_select(selected); + selected = ui->SelectMenu(selected); break; - case HIGHLIGHT_DOWN: + case Device::kHighlightDown: ++selected; - selected = ui_menu_select(selected); + selected = ui->SelectMenu(selected); break; - case SELECT_ITEM: + case Device::kInvokeItem: chosen_item = selected; break; - case NO_ACTION: + case Device::kNoAction: break; } } else if (!menu_only) { @@ -468,7 +471,7 @@ get_menu_selection(const char* const * headers, const char* const * items, } } - ui_end_menu(); + ui->EndMenu(); return chosen_item; } @@ -478,7 +481,7 @@ static int compare_string(const void* a, const void* b) { static int update_directory(const char* path, const char* unmount_when_done, - int* wipe_cache) { + int* wipe_cache, Device* device) { ensure_path_mounted(path); const char* MENU_HEADERS[] = { "Choose a package to install:", @@ -552,7 +555,7 @@ update_directory(const char* path, const char* unmount_when_done, int result; int chosen_item = 0; do { - chosen_item = get_menu_selection(headers, zips, 1, chosen_item); + chosen_item = get_menu_selection(headers, zips, 1, chosen_item, device); char* item = zips[chosen_item]; int item_len = strlen(item); @@ -567,7 +570,7 @@ update_directory(const char* path, const char* unmount_when_done, strlcat(new_path, "/", PATH_MAX); strlcat(new_path, item, PATH_MAX); new_path[strlen(new_path)-1] = '\0'; // truncate the trailing '/' - result = update_directory(new_path, unmount_when_done, wipe_cache); + result = update_directory(new_path, unmount_when_done, wipe_cache, device); if (result >= 0) break; } else { // selected a zip file: attempt to install it, and return @@ -577,7 +580,7 @@ update_directory(const char* path, const char* unmount_when_done, strlcat(new_path, "/", PATH_MAX); strlcat(new_path, item, PATH_MAX); - ui_print("\n-- Install %s ...\n", path); + ui->Print("\n-- Install %s ...\n", path); set_sdcard_update_bootloader_message(); char* copy = copy_sideloaded_package(new_path); if (unmount_when_done != NULL) { @@ -605,7 +608,7 @@ update_directory(const char* path, const char* unmount_when_done, } static void -wipe_data(int confirm) { +wipe_data(int confirm, Device* device) { if (confirm) { static const char** title_headers = NULL; @@ -630,96 +633,96 @@ wipe_data(int confirm) { " No", NULL }; - int chosen_item = get_menu_selection(title_headers, items, 1, 0); + int chosen_item = get_menu_selection(title_headers, items, 1, 0, device); if (chosen_item != 7) { return; } } - ui_print("\n-- Wiping data...\n"); - device_wipe_data(); + ui->Print("\n-- Wiping data...\n"); + device->WipeData(); erase_volume("/data"); erase_volume("/cache"); - ui_print("Data wipe complete.\n"); + ui->Print("Data wipe complete.\n"); } static void -prompt_and_wait() { - const char** headers = prepend_title((const char**)MENU_HEADERS); +prompt_and_wait(Device* device) { + const char* const* headers = prepend_title(device->GetMenuHeaders()); for (;;) { finish_recovery(NULL); - ui_reset_progress(); + ui->SetProgressType(RecoveryUI::EMPTY); - int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); + int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. - chosen_item = device_perform_action(chosen_item); + chosen_item = device->InvokeMenuItem(chosen_item); int status; int wipe_cache; switch (chosen_item) { - case ITEM_REBOOT: + case Device::REBOOT: return; - case ITEM_WIPE_DATA: - wipe_data(ui_text_visible()); - if (!ui_text_visible()) return; + case Device::WIPE_DATA: + wipe_data(ui->IsTextVisible(), device); + if (!ui->IsTextVisible()) return; break; - case ITEM_WIPE_CACHE: - ui_print("\n-- Wiping cache...\n"); + case Device::WIPE_CACHE: + ui->Print("\n-- Wiping cache...\n"); erase_volume("/cache"); - ui_print("Cache wipe complete.\n"); - if (!ui_text_visible()) return; + ui->Print("Cache wipe complete.\n"); + if (!ui->IsTextVisible()) return; break; - case ITEM_APPLY_SDCARD: - status = update_directory(SDCARD_ROOT, SDCARD_ROOT, &wipe_cache); + case Device::APPLY_EXT: + status = update_directory(SDCARD_ROOT, SDCARD_ROOT, &wipe_cache, device); if (status == INSTALL_SUCCESS && wipe_cache) { - ui_print("\n-- Wiping cache (at package request)...\n"); + ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { - ui_print("Cache wipe failed.\n"); + ui->Print("Cache wipe failed.\n"); } else { - ui_print("Cache wipe complete.\n"); + ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { - ui_set_background(BACKGROUND_ICON_ERROR); - ui_print("Installation aborted.\n"); - } else if (!ui_text_visible()) { + ui->SetBackground(RecoveryUI::ERROR); + ui->Print("Installation aborted.\n"); + } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { - ui_print("\nInstall from sdcard complete.\n"); + ui->Print("\nInstall from sdcard complete.\n"); } } break; - case ITEM_APPLY_CACHE: + + case Device::APPLY_CACHE: // Don't unmount cache at the end of this. - status = update_directory(CACHE_ROOT, NULL, &wipe_cache); + status = update_directory(CACHE_ROOT, NULL, &wipe_cache, device); if (status == INSTALL_SUCCESS && wipe_cache) { - ui_print("\n-- Wiping cache (at package request)...\n"); + ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { - ui_print("Cache wipe failed.\n"); + ui->Print("Cache wipe failed.\n"); } else { - ui_print("Cache wipe complete.\n"); + ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { - ui_set_background(BACKGROUND_ICON_ERROR); - ui_print("Installation aborted.\n"); - } else if (!ui_text_visible()) { + ui->SetBackground(RecoveryUI::ERROR); + ui->Print("Installation aborted.\n"); + } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { - ui_print("\nInstall from cache complete.\n"); + ui->Print("\nInstall from cache complete.\n"); } } break; - } } } @@ -738,9 +741,11 @@ main(int argc, char **argv) { freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); printf("Starting recovery on %s", ctime(&start)); - device_ui_init(&ui_parameters); - ui_init(); - ui_set_background(BACKGROUND_ICON_INSTALLING); + Device* device = make_device(); + ui = device->GetUI(); + + ui->Init(); + ui->SetBackground(RecoveryUI::INSTALLING); load_volume_table(); get_args(&argc, &argv); @@ -757,14 +762,14 @@ main(int argc, char **argv) { case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; - case 't': ui_show_text(1); break; + case 't': ui->ShowText(true); break; case '?': LOGE("Invalid command argument\n"); continue; } } - device_recovery_start(); + device->StartRecovery(); printf("Command:"); for (arg = 0; arg < argc; arg++) { @@ -800,27 +805,27 @@ main(int argc, char **argv) { LOGE("Cache wipe (requested by package) failed."); } } - if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); + if (status != INSTALL_SUCCESS) ui->Print("Installation aborted.\n"); } else if (wipe_data) { - if (device_wipe_data()) status = INSTALL_ERROR; + if (device->WipeData()) status = INSTALL_ERROR; if (erase_volume("/data")) status = INSTALL_ERROR; if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; - if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); + if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); } else if (wipe_cache) { if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; - if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n"); + if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); } else { status = INSTALL_ERROR; // No command specified } - if (status != INSTALL_SUCCESS) ui_set_background(BACKGROUND_ICON_ERROR); - if (status != INSTALL_SUCCESS || ui_text_visible()) { - prompt_and_wait(); + if (status != INSTALL_SUCCESS) ui->SetBackground(RecoveryUI::ERROR); + if (status != INSTALL_SUCCESS || ui->IsTextVisible()) { + prompt_and_wait(device); } // Otherwise, get ready to boot the main system... finish_recovery(send_intent); - ui_print("Rebooting...\n"); + ui->Print("Rebooting...\n"); android_reboot(ANDROID_RB_RESTART, 0, 0); return EXIT_SUCCESS; } |