From 8b7334b3c2f891f516722851575fec43bd28b4cf Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 10 Feb 2009 15:43:56 -0800 Subject: auto import from //branches/cupcake/...@130745 --- recovery.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 23 deletions(-) (limited to 'recovery.c') diff --git a/recovery.c b/recovery.c index 3d44df3b4..221ee2975 100644 --- a/recovery.c +++ b/recovery.c @@ -291,17 +291,32 @@ erase_root(const char *root) static void prompt_and_wait() { - ui_print("\n" - "Home+Back - reboot system now\n" - "Alt+L - toggle log text display\n" - "Alt+S - apply sdcard:update.zip\n" - "Alt+W - wipe data/factory reset\n"); - + char* headers[] = { "Android system recovery utility", + "", + "Use trackball to highlight;", + "click to select.", + "", + NULL }; + + // these constants correspond to elements of the items[] list. +#define ITEM_REBOOT 0 +#define ITEM_APPLY_SDCARD 1 +#define ITEM_WIPE_DATA 2 + char* items[] = { "reboot system now [Home+Back]", + "apply sdcard:update.zip [Alt+S]", + "wipe data/factory reset [Alt+W]", + NULL }; + + ui_start_menu(headers, items); + int selected = 0; + int chosen_item = -1; + + finish_recovery(NULL); + ui_reset_progress(); for (;;) { - finish_recovery(NULL); - ui_reset_progress(); int key = ui_wait_key(); int alt = ui_key_pressed(KEY_LEFTALT) || ui_key_pressed(KEY_RIGHTALT); + int visible = ui_text_visible(); if (key == KEY_DREAM_BACK && ui_key_pressed(KEY_DREAM_HOME)) { // Wait for the keys to be released, to avoid triggering @@ -310,23 +325,64 @@ prompt_and_wait() ui_key_pressed(KEY_DREAM_HOME)) { usleep(1000); } - break; + chosen_item = ITEM_REBOOT; } else if (alt && key == KEY_W) { - ui_print("\n"); - erase_root("DATA:"); - erase_root("CACHE:"); - ui_print("Data wipe complete.\n"); - if (!ui_text_visible()) break; + chosen_item = ITEM_WIPE_DATA; } else if (alt && key == KEY_S) { - ui_print("\nInstalling from sdcard...\n"); - int status = install_package(SDCARD_PACKAGE_FILE); - if (status != INSTALL_SUCCESS) { - ui_set_background(BACKGROUND_ICON_ERROR); - ui_print("Installation aborted.\n"); - } else if (!ui_text_visible()) { - break; // reboot if logs aren't visible + chosen_item = ITEM_APPLY_SDCARD; + } else if ((key == KEY_DOWN || key == KEY_VOLUMEDOWN) && visible) { + ++selected; + selected = ui_menu_select(selected); + } else if ((key == KEY_UP || key == KEY_VOLUMEUP) && visible) { + --selected; + selected = ui_menu_select(selected); + } else if (key == BTN_MOUSE && visible) { + chosen_item = selected; + } + + if (chosen_item >= 0) { + // turn off the menu, letting ui_print() to scroll output + // on the screen. + ui_end_menu(); + + switch (chosen_item) { + case ITEM_REBOOT: + return; + + case ITEM_WIPE_DATA: + ui_print("\n-- Wiping data...\n"); + erase_root("DATA:"); + erase_root("CACHE:"); + ui_print("Data wipe complete.\n"); + if (!ui_text_visible()) return; + break; + + case ITEM_APPLY_SDCARD: + ui_print("\n-- Install from sdcard...\n"); + int status = install_package(SDCARD_PACKAGE_FILE); + if (status != INSTALL_SUCCESS) { + ui_set_background(BACKGROUND_ICON_ERROR); + ui_print("Installation aborted.\n"); + } else if (!ui_text_visible()) { + return; // reboot if logs aren't visible + } else { + ui_print("Install from sdcard complete.\n"); + } + break; } - ui_print("\nPress Home+Back to reboot\n"); + + // if we didn't return from this function to reboot, show + // the menu again. + ui_start_menu(headers, items); + selected = 0; + chosen_item = -1; + + finish_recovery(NULL); + ui_reset_progress(); + + // throw away keys pressed while the command was running, + // so user doesn't accidentally trigger menu items. + ui_clear_key_queue(); } } } @@ -348,7 +404,6 @@ main(int argc, char **argv) fprintf(stderr, "Starting recovery on %s", ctime(&start)); ui_init(); - ui_print("Android system recovery utility\n"); get_args(&argc, &argv); int previous_runs = 0; -- cgit v1.2.3