static void prompt_and_wait() { char** headers = prepend_title(MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); ui_set_background(BACKGROUND_ICON_ERROR); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0); // 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); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_APPLY_SDCARD: show_install_update_menu(); /* ui_print("\n-- Install from sdcard...\n"); set_sdcard_update_bootloader_message(); 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("\nInstall from sdcard complete.\n"); } */ break; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); erase_root("CACHE:"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; break; case ITEM_ADVANCED: show_advanced_menu(); break; } } }
static void wipe_data(int confirm) { if (confirm) { static char** title_headers = NULL; if (title_headers == NULL) { char* headers[] = { "Confirm wipe of all user data?", " THIS CAN NOT BE UNDONE.", "", NULL }; title_headers = prepend_title(headers); } char* items[] = { " No", " No", " No", " No", " No", " No", " No", " Yes -- delete all user data", // [7] " No", " No", " No", NULL }; int chosen_item = get_menu_selection(title_headers, items, 1); if (chosen_item != 7) { return; } } ui_print("\n-- Wiping data...\n"); device_wipe_data(); erase_root("DATA:"); #ifdef BOARD_HAS_DATADATA erase_root("DATADATA:"); #endif erase_root("CACHE:"); erase_root("SDEXT:"); erase_root("SDCARD:/.android_secure"); ui_print("Data wipe complete.\n"); }
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"); for (;;) { finish_recovery(NULL); ui_reset_progress(); int key = ui_wait_key(); int alt = ui_key_pressed(KEY_LEFTALT) || ui_key_pressed(KEY_RIGHTALT); if (key == KEY_DREAM_BACK && ui_key_pressed(KEY_DREAM_HOME)) { // Wait for the keys to be released, to avoid triggering // special boot modes (like coming back into recovery!). while (ui_key_pressed(KEY_DREAM_BACK) || ui_key_pressed(KEY_DREAM_HOME)) { usleep(1000); } break; } 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; } 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 } ui_print("\nPress Home+Back to reboot\n"); } } }
static void wipe_data(int confirm) { if (confirm) { char* headers[] = { "Confirm wipe of all user data?", " THIS CAN NOT BE UNDONE.", "", NULL }; char* items[] = { " No", " No", " No", " No", " No", " No", " No", " Yes -- delete all user data", // [7] " No", " No", " No", NULL }; int chosen_item = show_interactive_menu(headers, items); hide_menu_selection(); if (chosen_item != 8) return; } ui_led_blink(1); ui_print("\n-- Wiping data...\n"); device_wipe_data(); erase_root("DATA:"); erase_root("CACHE:"); ensure_common_roots_mounted(); ui_print("Data wipe complete.\n"); ui_led_toggle(0); }
int main(int argc, char **argv) { if (strstr(argv[0], "recovery") == NULL) { if (strstr(argv[0], "flash_image") != NULL) return flash_image_main(argc, argv); if (strstr(argv[0], "dump_image") != NULL) return dump_image_main(argc, argv); if (strstr(argv[0], "erase_image") != NULL) return erase_image_main(argc, argv); if (strstr(argv[0], "mkyaffs2image") != NULL) return mkyaffs2image_main(argc, argv); if (strstr(argv[0], "unyaffs") != NULL) return unyaffs_main(argc, argv); if (strstr(argv[0], "amend")) return amend_main(argc, argv); if (strstr(argv[0], "nandroid")) return nandroid_main(argc, argv); if (strstr(argv[0], "reboot")) return reboot_main(argc, argv); if (strstr(argv[0], "setprop")) return setprop_main(argc, argv); return busybox_driver(argc, argv); } __system("/sbin/postrecoveryboot.sh"); create_fstab(); int is_user_initiated_recovery = 0; time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); fprintf(stderr, "Starting recovery on %s", ctime(&start)); ui_init(); ui_print(EXPAND(RECOVERY_VERSION)"\n"); #ifdef BOARD_GOAPK_DEFY ui_print(EXPAND(RECOVERY_VERSION_GOAPK)"\n"); ui_print(EXPAND(RECOVERY_VERSION_QUN)"\n"); #endif get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case '?': LOGE("Invalid command argument\n"); continue; } } device_recovery_start(); fprintf(stderr, "Command:"); for (arg = 0; arg < argc; arg++) { fprintf(stderr, " \"%s\"", argv[arg]); } fprintf(stderr, "\n\n"); property_list(print_property, NULL); fprintf(stderr, "\n"); int status = INSTALL_SUCCESS; RecoveryCommandContext ctx = { NULL }; if (register_update_commands(&ctx)) { LOGE("Can't install update commands\n"); } if (update_package != NULL) { if (wipe_data && erase_root("DATA:")) status = INSTALL_ERROR; status = install_package(update_package); if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); } else if (wipe_data) { if (device_wipe_data()) status = INSTALL_ERROR; if (erase_root("DATA:")) status = INSTALL_ERROR; if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); } else if (wipe_cache) { if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n"); } else { LOGI("Checking for extendedcommand...\n"); status = INSTALL_ERROR; // No command specified // we are starting up in user initiated recovery here // let's set up some default options signature_check_enabled = 0; script_assert_enabled = 0; is_user_initiated_recovery = 1; ui_set_show_text(1); if (extendedcommand_file_exists()) { LOGI("Running extendedcommand...\n"); int ret; if (0 == (ret = run_and_remove_extendedcommand())) { status = INSTALL_SUCCESS; ui_set_show_text(0); } else { handle_failure(ret); } } else { LOGI("Skipping execution of extendedcommand, file not found...\n"); } } if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) ui_set_background(BACKGROUND_ICON_ERROR); if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait(); #ifndef BOARD_HAS_NO_MISC_PARTITION // If there is a radio image pending, reboot now to install it. maybe_install_firmware_update(send_intent); #endif // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui_print("Rebooting...\n"); sync(); reboot(RB_AUTOBOOT); return EXIT_SUCCESS; }
static void prompt_and_wait() { char** headers = prepend_title(MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); allow_display_toggle = 1; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0); allow_display_toggle = 0; // 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); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache")) { ui_print("\n-- Wiping cache...\n"); erase_root("CACHE:"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; } break; case ITEM_APPLY_SDCARD: if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip")) { ui_print("\n-- Install from sdcard...\n"); #ifndef BOARD_HAS_NO_MISC_PARTITION set_sdcard_update_bootloader_message(); #endif 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 { #ifndef BOARD_HAS_NO_MISC_PARTITION if (firmware_update_pending()) { ui_print("\nReboot via menu to complete\n" "installation.\n"); } else { ui_print("\nInstall from sdcard complete.\n"); } #else ui_print("\nInstall from sdcard complete.\n"); #endif } } break; case ITEM_INSTALL_ZIP: show_install_update_menu(); break; case ITEM_NANDROID: show_nandroid_menu(); break; case ITEM_PARTITION: show_partition_menu(); break; case ITEM_ADVANCED: show_advanced_menu(); break; } } }
int main(int argc, char **argv) { time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); 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; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case '?': LOGE("Invalid command argument\n"); continue; } } fprintf(stderr, "Command:"); for (arg = 0; arg < argc; arg++) { fprintf(stderr, " \"%s\"", argv[arg]); } fprintf(stderr, "\n\n"); property_list(print_property, NULL); fprintf(stderr, "\n"); #if TEST_AMEND test_amend(); #endif RecoveryCommandContext ctx = { NULL }; if (register_update_commands(&ctx)) { LOGE("Can't install update commands\n"); } int status = INSTALL_SUCCESS; if (update_package != NULL) { status = install_package(update_package); if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); } else if (wipe_data || wipe_cache) { if (wipe_data && erase_root("DATA:")) status = INSTALL_ERROR; if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Data 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 there is a radio image pending, reboot now to install it. maybe_install_firmware_update(send_intent); // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui_print("Rebooting...\n"); sync(); reboot(RB_AUTOBOOT); return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (strstr(argv[0], "recovery") == NULL) { if (strstr(argv[0], "flash_image") != NULL) return flash_image_main(argc, argv); if (strstr(argv[0], "dump_image") != NULL) return dump_image_main(argc, argv); if (strstr(argv[0], "erase_image") != NULL) return erase_image_main(argc, argv); if (strstr(argv[0], "mkyaffs2image") != NULL) return mkyaffs2image_main(argc, argv); if (strstr(argv[0], "unyaffs") != NULL) return unyaffs_main(argc, argv); if (strstr(argv[0], "nandroid")) return nandroid_main(argc, argv); if (strstr(argv[0], "reboot")) return reboot_main(argc, argv); if (strstr(argv[0], "setprop")) return setprop_main(argc, argv); if (strstr(argv[0], "getprop")) return getprop_main(argc, argv); return busybox_driver(argc, argv); } int is_user_initiated_recovery = 0; time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); fprintf(stderr, "Starting recovery on %s", ctime(&start)); ui_init(); ui_print(EXPAND(RECOVERY_VERSION)"\n"); //get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case '?': LOGE("Invalid command argument\n"); continue; } } //device_recovery_start(); fprintf(stderr, "Command:"); for (arg = 0; arg < argc; arg++) { fprintf(stderr, " \"%s\"", argv[arg]); } fprintf(stderr, "\n\n"); property_list(print_property, NULL); fprintf(stderr, "\n"); int status = INSTALL_SUCCESS; //Register amend commands RecoveryCommandContext ctx = { NULL }; if (register_update_commands(&ctx)) { LOGE("Can't install update commands\n"); } if (update_package != NULL) { status = install_package(update_package); if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); } else if (wipe_data) { if (device_wipe_data()) status = INSTALL_ERROR; if (erase_root("DATA:")) status = INSTALL_ERROR; if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); } else if (wipe_cache) { if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n"); } else { status = INSTALL_ERROR; // No command specified } if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait(); // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui_print("Rebooting...\n"); sync(); reboot(RB_AUTOBOOT); return EXIT_SUCCESS; }
static void prompt_and_wait() { char* menu_files[MAX_MENU_LEVEL] = { NULL }; char* menu_scripts[MAX_MENU_LEVEL] = { NULL }; int menu_sel[MAX_MENU_LEVEL] = { 0 }; unsigned int menu_level = 0; int menu_result; //always ensure if mountings are good ensure_common_roots_mounted(); //initialize the recovery -> either call the script for initalization, or switch to full version #if !OPEN_RCVR_VERSION_LITE run_shell_script("/bin/init_recovery.sh "OPEN_RECOVERY_PHONE_SWITCH, 1, NULL); #endif menu_files[0] = malloc(strlen(MAIN_MENU_FILE)+1); strcpy(menu_files[0], MAIN_MENU_FILE); ui_led_blink(1); create_menu(menu_files[0], menu_scripts[0]); ui_led_toggle(0); int title_length; char** headers; headers = prepend_title(MENU_HEADERS, &title_length); int override_initial_selection = -1; int call_finish_in_loop = 1; for (;;) { if (call_finish_in_loop) { finish_recovery(NULL); call_finish_in_loop = 0; } int menu_item; if (override_initial_selection != -1) { menu_item = get_menu_selection(headers, MENU_ITEMS, MENU_ITEMS_SELECTABLE, title_length, override_initial_selection, 0); override_initial_selection = -1; } else menu_item = get_menu_selection(headers, MENU_ITEMS, MENU_ITEMS_SELECTABLE, title_length, 0, 0); // Parse open recovery commands int chosen_item = select_action(menu_item); chosen_item = device_perform_action(chosen_item); //if tag, menu, or scripted menu -> don't hide menu //do it here explicitly, it would be a mess in the switch if (chosen_item != ITEM_TAG && chosen_item != ITEM_NEW_MENU && chosen_item != ITEM_NEW_MENU_SCRIPTED) hide_menu_selection(); fprintf(stderr, "Menu: %d, %d, %s\n", menu_item, chosen_item, MENU_ITEMS_TARGET[menu_item]); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; ui_set_background(BACKGROUND_ICON_ERROR); break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); ui_led_blink(1); erase_root("CACHE:"); ensure_common_roots_mounted(); ui_led_toggle(0); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; ui_set_background(BACKGROUND_ICON_ERROR); break; case ITEM_APPLY_SDCARD: //HACK for "error: a label can only be part of a statement and a declaration is not a statement" //the rule is retarted, the follwing "dummy" statement is cut in optimization override_initial_selection=override_initial_selection; //confirm it char* confirm_headers[] = { "Confirm installing update package?", MENU_ITEMS[menu_item], "", NULL }; char* confirm_items[] = { "Yes", "No", NULL }; int confirm_item = show_interactive_menu(confirm_headers, confirm_items); if (confirm_item == 1) //YES! { ui_print("\n-- Install from sdcard...\n"); ui_led_blink(1); ensure_common_roots_unmounted(); ensure_root_path_mounted("SDCARD:"); set_sdcard_update_bootloader_message(); call_finish_in_loop = 1; int status = install_package(MENU_ITEMS_TARGET[menu_item]); ensure_common_roots_mounted(); 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 { if (firmware_update_pending()) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("\nReboot via menu to complete\n" "installation.\n"); } else { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("\nInstall from sdcard complete.\n"); } } create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); } override_initial_selection = menu_item; break; case ITEM_SHELL_SCRIPT: ui_print("\n-- Shell script...\n"); ui_print("%s\n", MENU_ITEMS_TARGET[menu_item]); ui_led_blink(1); ensure_common_roots_mounted(); run_shell_script(MENU_ITEMS_TARGET[menu_item], 1, NULL); create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); ui_print("Done.\n"); override_initial_selection = menu_item; break; case ITEM_TAG: if (MENU_ITEMS_TAG[menu_item] == 0x00) { int tag_fd = creat(MENU_ITEMS_TARGET[menu_item], 0644); if (tag_fd < 0) LOGE("Failed to set the tag.\n"); else { MENU_ITEMS_TAG[menu_item] = 0x01; MENU_ITEMS[menu_item][1] = 'X'; close(tag_fd); } } else if (MENU_ITEMS_TAG[menu_item] == 0x01) //just a little check if 0xFF aint there if bug is present { remove(MENU_ITEMS_TARGET[menu_item]); MENU_ITEMS_TAG[menu_item] = 0x00; MENU_ITEMS[menu_item][1] = ' '; } override_initial_selection = menu_item; break; case ITEM_NEW_MENU: if (menu_level + 1 >= MAX_MENU_LEVEL) { //too much menus, ignore break; } ui_led_blink(1); if (!strcmp(MENU_ITEMS_TARGET[menu_item], "..")) { if (menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_sel[menu_level] = 0; menu_level--; override_initial_selection = menu_sel[menu_level]; } } else { menu_sel[menu_level] = menu_item; menu_level++; menu_files[menu_level] = malloc(strlen(MENU_ITEMS_TARGET[menu_item]) + 1); strcpy(menu_files[menu_level], MENU_ITEMS_TARGET[menu_item]); } ensure_common_roots_mounted(); menu_result = create_menu(menu_files[menu_level], menu_scripts[menu_level]); //if fail, remove the new menu if (menu_result && menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_level--; } free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); break; case ITEM_NEW_MENU_SCRIPTED: if (menu_level + 1 >= MAX_MENU_LEVEL) { //too much menus, ignore break; } ui_led_blink(1); char cmdBuff[MAX_LINE_LENGTH]; strcpy(cmdBuff, MENU_ITEMS_TARGET[menu_item]); char* ptr; //menufile:script ptr = strtok(cmdBuff, ":"); if (ptr != NULL) { menu_sel[menu_level] = menu_item; menu_level++; menu_files[menu_level] = malloc(strlen(ptr) + 1); strcpy(menu_files[menu_level], ptr); ptr = strtok(NULL, ""); if (ptr != NULL) { if (ptr[0] == '/' || (ptr[0] == '\"' && ptr[1] == '/')) { menu_scripts[menu_level] = malloc(strlen(ptr) + 1); strcpy(menu_scripts[menu_level], ptr); } else { menu_scripts[menu_level] = malloc(strlen(CUSTOM_SHELL_SCRIPT_PATH) + strlen(ptr) + 2); if (ptr[0] == '\"') sprintf(menu_scripts[menu_level], "\"%s/%s", CUSTOM_SHELL_SCRIPT_PATH, ptr+1); else sprintf(menu_scripts[menu_level], "%s/%s", CUSTOM_SHELL_SCRIPT_PATH, ptr); } } ensure_common_roots_mounted(); menu_result = create_menu(menu_files[menu_level], menu_scripts[menu_level]); //if fail, remove the new menu if (menu_result && menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_level--; } free(headers); headers = prepend_title(MENU_HEADERS, &title_length); } ui_led_toggle(0); break; case ITEM_CONSOLE: #if OPEN_RECOVERY_HAVE_CONSOLE ensure_common_roots_mounted(); ui_print("Opening console...\n"); int console_error = run_console(NULL); if (console_error) if (console_error == CONSOLE_FORCE_QUIT) ui_print("Console was forcibly closed.\n"); else if (console_error == CONSOLE_FAILED_START) ui_print("Console failed to start.\n"); else { ui_print("Closing console...\n"); //don't bother printing error to UI fprintf(stderr, "Console closed with error %d.\n", console_error); } else ui_print("Closing console...\n"); create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); #else LOGE("This phone doesn't support console.\n"); #endif override_initial_selection = menu_item; break; case ITEM_ERROR: LOGE("Unknown command: %s.\n", MENU_ITEMS_ACTION[menu_item]); break; } } }
int main(int argc, char **argv) { if (getppid() != 1) { fprintf(stderr, "Parent process must be init.\n"); return EXIT_FAILURE; } time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); fprintf(stderr, "Starting Open Recovery on %s", ctime(&start)); //menu title //lite - just the base //full - look for mod #if OPEN_RCVR_VERSION_LITE MENU_TITLE = BASE_MENU_TITLE; #else //keep'em malloced even if empty :p char* mod_author = malloc(81); char* mod_version = malloc(81); char mod_author_prop[81]; char mod_version_prop[81]; property_get(MOD_AUTHOR_PROP, mod_author_prop, ""); property_get(MOD_VERSION_PROP, mod_version_prop, ""); //assume there are some mod properties, leave NULL if there ain't MENU_TITLE = malloc((sizeof(BASE_MENU_TITLE) + 3) * sizeof(char*)); memset(MENU_TITLE, 0, (sizeof(BASE_MENU_TITLE) + 3) * sizeof(char*)); char** b = BASE_MENU_TITLE; char** m = MENU_TITLE; while (*b) { *m = *b; m++; b++; } //append "" if one of the props exist int append_empty = 0; if (mod_author_prop[0] != '\0') { //mod version only if mod author if (mod_version_prop[0] != '\0') { snprintf(mod_version, 80, MOD_VERSION_BASE, mod_version_prop); *m = mod_version; m++; } snprintf(mod_author, 80, MOD_AUTHOR_BASE, mod_author_prop); *m = mod_author; m++; append_empty = 1; } if (append_empty) { *m = malloc(1); (*m)[0] = '\0'; m++; } #endif ui_init(); //react on the command //full version only checks for it's own command file //the rest is done by lite version #if OPEN_RCVR_VERSION_LITE get_args(&argc, &argv); #else argc = 1; get_cmd_file_args(&argc, &argv); #endif int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case '?': LOGE("Invalid command argument\n"); continue; } } device_recovery_start(); fprintf(stderr, "Command:"); for (arg = 0; arg < argc; arg++) fprintf(stderr, " \"%s\"", argv[arg]); fprintf(stderr, "\n\n"); property_list(print_property, NULL); fprintf(stderr, "\n"); int status = INSTALL_SUCCESS; if (update_package != NULL) { status = install_package(update_package); if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); char package_path[PATH_MAX] = ""; if (!ensure_root_path_mounted(update_package) && translate_root_path(update_package, package_path, sizeof(package_path))) unlink(package_path); } else if (wipe_data) { if (device_wipe_data()) status = INSTALL_ERROR; if (erase_root("DATA:")) status = INSTALL_ERROR; if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); } else if (wipe_cache) { if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n"); } else status = INSTALL_ERROR; // No command specified #if OPEN_RCVR_VERSION_LITE int or_up_sts = install_package(FULL_PACKAGE_FILE); if (or_up_sts != INSTALL_SUCCESS) { ui_print("Failed to switch into the full version.\n"); ui_print("Running Lite version only.\n"); } #endif //lite OR doesn't have text visible by default //but full OR does #if OPEN_RCVR_VERSION_LITE if (status != INSTALL_SUCCESS) ui_set_background(BACKGROUND_ICON_ERROR); if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait(); #else if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); prompt_and_wait(); } #endif // If there is a radio image pending, reboot now to install it. maybe_install_firmware_update(send_intent); // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui_print("Rebooting...\n"); sync(); ensure_common_roots_unmounted(); reboot(RB_AUTOBOOT); return EXIT_SUCCESS; }