diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2009-03-19 00:57:16 +0100 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2009-03-19 00:57:16 +0100 |
commit | c5c389f8f2b43a640667aa53ee3e369033c55569 (patch) | |
tree | 7df23711566b358047301d8413ee399105546e8b /recovery.c | |
parent | Remove obsolete OTA tools (diff) | |
parent | auto import from //depot/cupcake/@135843 (diff) | |
download | android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.tar android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.tar.gz android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.tar.bz2 android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.tar.lz android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.tar.xz android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.tar.zst android_bootable_recovery-c5c389f8f2b43a640667aa53ee3e369033c55569.zip |
Diffstat (limited to 'recovery.c')
-rw-r--r-- | recovery.c | 101 |
1 files changed, 78 insertions, 23 deletions
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; |