static int oppo_wipe_items(int item) { intentResult*result1; int ret1; int ret2; int wipe_result = WIPE_IGNORE; switch(item) { case WIPE_FACTORY: oppo_debug("WIPE_FACTORY\n"); wipe_thread_start("<~wipe.factory.name>"); set_sdcard_update_bootloader_message("--wipe_data", NULL); LOGW("Erase data and cache write bcb...\n"); result1 = oppoIntent_send(INTENT_WIPE, 1, "/data"); ret1 = result1->ret; set_wipe_process(50); result1 = oppoIntent_send(INTENT_WIPE, 1, "/cache"); ret2 = result1->ret; oppo_debug("result1=%d, result2=%d\n", ret1, ret2); if ((ret1 == 0) && (ret2 == 0)) { wipe_result = WIPE_ALL_OK; } else { wipe_result = WIPE_ALL_FAILED; } break; case WIPE_DATA: oppo_debug("WIPE_DATA\n"); wipe_thread_start("<~wipe.data.name>"); set_sdcard_update_bootloader_message("--wipe_data_only", NULL); LOGW("Erase data write bcb...\n"); result1 = oppoIntent_send(INTENT_WIPE, 1, "/data"); if (result1->ret == 0) { wipe_result = WIPE_DATA_OK; } else { wipe_result = WIPE_DATA_FAILED; } break; case WIPE_CACHE: oppo_debug("WIPE_CACHE\n"); wipe_thread_start("<~wipe.cache.name>"); set_sdcard_update_bootloader_message("--wipe_cache", NULL); LOGW("Erase cache write bcb...\n"); result1 = oppoIntent_send(INTENT_WIPE, 1, "/cache"); if (result1->ret == 0) { wipe_result = WIPE_CACHE_OK; } else { wipe_result = WIPE_CACHE_FAILED; } break; default: assert_if_fail(0); break; } set_wipe_process(100); wipe_thread_close(); return wipe_result; }
int install_update_zip(char* filename) { char *path = NULL; puts(filename); path = replace_str(filename, "/sdcard/", "SDCARD:"); ui_print("\n-- Install update.zip from sdcard...\n"); set_sdcard_update_bootloader_message(); ui_print("Attempting update from...\n"); ui_print(filename); ui_print("\n"); int status = install_package(path); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); return 0; } else if (!ui_text_visible()) { return 0; // reboot if logs aren't visible } else { if (firmware_update_pending()) { ui_print("\nReboot via menu to complete\ninstallation.\n"); return 0; } else { ui_print("\nInstall from sdcard complete.\n"); ui_print("\nThanks for using RZrecovery.\n"); } } return 0; }
int install_update_zip (char *filename) { char *path = NULL; puts (filename); ui_print ("\n-- Install update.zip from sdcard...\n"); set_sdcard_update_bootloader_message (); ui_print ("Attempting update from...\n"); ui_print ("%s", filename); ui_print ("\n"); int status = install_package (filename); if (status != INSTALL_SUCCESS) { ui_set_background (BACKGROUND_ICON_RZ); ui_print ("Installation aborted.\n"); return 0; } else { ui_print ("\nInstall from sdcard complete.\n"); ui_print ("\nThanks for using RZrecovery.\n"); } return 0; }
int install_zip(const char* packagefilepath) { ui_print("\n-- Installing: %s\n", packagefilepath); set_sdcard_update_bootloader_message(); // will ensure_path_mounted(packagefilepath) // will also set background icon to installing and indeterminate progress bar int wipe_cache = 0; int status = install_package(packagefilepath, &wipe_cache, TEMPORARY_INSTALL_FILE); ui_reset_progress(); if (status != INSTALL_SUCCESS) { copy_logs(); ui_set_background(BACKGROUND_ICON_ERROR); LOGE("Installation aborted.\n"); return 1; } else if (wipe_cache && erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed.\n"); } #ifdef PHILZ_TOUCH_RECOVERY if (show_background_icon.value) ui_set_background(BACKGROUND_ICON_CLOCKWORK); else #endif ui_set_background(BACKGROUND_ICON_NONE); ui_print("\nInstall from sdcard complete.\n"); return 0; }
static void prompt_and_wait() { char** headers = prepend_title(MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); 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_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_APPLY_SDCARD: 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; } } }
int install_zip(const char* packagefilepath) { ui_print("\n-- Installing: %s\n", packagefilepath); if (device_flash_type() == MTD) { set_sdcard_update_bootloader_message(); } int status = install_package(packagefilepath); ui_reset_progress(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); return 1; } ui_set_background(BACKGROUND_ICON_NONE); ui_print("\nInstall from sdcard complete.\n"); return 0; }
int install_zip(const char* packagefilepath) { ui_print("\n-- 正在安装: %s\n", packagefilepath); if (device_flash_type() == MTD) { set_sdcard_update_bootloader_message(); } int status = install_package(packagefilepath); ui_reset_progress(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("安装已取消.\n"); return 1; } ui_set_background(BACKGROUND_ICON_NONE); ui_print("\n从SD卡安装刷机包成功!\n"); return 0; }
int install_zip(const char* packagefilepath) { ui_print("\n-- Installing: %s\n", packagefilepath); #ifndef BOARD_HAS_NO_MISC_PARTITION set_sdcard_update_bootloader_message(); #endif int status = install_package(packagefilepath); ui_reset_progress(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); return 1; } #ifndef BOARD_HAS_NO_MISC_PARTITION if (firmware_update_pending()) { ui_print("\nReboot via menu to complete\ninstallation.\n"); } #endif ui_set_background(BACKGROUND_ICON_EBCLOCKWORK); ui_print("\nInstall from sdcard complete.\n"); return 0; }
/* add by cjcheng start... */ static int smdt_update_directory(const char* path, const char* unmount_when_done, int* wipe_cache) { ensure_path_mounted(path); int result; char new_path[PATH_MAX]; strlcpy(new_path, path, PATH_MAX); strlcat(new_path, "/", PATH_MAX); strlcat(new_path, "update.zip", PATH_MAX); ui->Print("\n-- Install %s ...\n", new_path); if (access(new_path, F_OK) == 0) { ui->Print("\n read -- %s ok...\n", new_path); ui->SetTipTitle(RecoveryUI::TIP_TITLE_READ_PACKAGE); } else { ui->Print("\n read -- %s error...\n", new_path); if (unmount_when_done != NULL) { ensure_path_unmounted(unmount_when_done); } return INSTALL_ERROR; } set_sdcard_update_bootloader_message(); char* copy = copy_sideloaded_package(new_path); if (unmount_when_done != NULL) { ensure_path_unmounted(unmount_when_done); } if (copy) { result = install_package(copy, wipe_cache, TEMPORARY_INSTALL_FILE); free(copy); } else { result = INSTALL_ERROR; } return result; }
static int update_directory(const char* path, const char* unmount_when_done, int* wipe_cache, Device* device) { ensure_path_mounted(path); const char* MENU_HEADERS[] = { "Choose a package to install:", path, "", NULL }; DIR* d; struct dirent* de; d = opendir(path); if (d == NULL) { LOGE("error opening %s: %s\n", path, strerror(errno)); if (unmount_when_done != NULL) { ensure_path_unmounted(unmount_when_done); } return 0; } const char** headers = prepend_title(MENU_HEADERS); int d_size = 0; int d_alloc = 10; char** dirs = (char**)malloc(d_alloc * sizeof(char*)); int z_size = 1; int z_alloc = 10; char** zips = (char**)malloc(z_alloc * sizeof(char*)); zips[0] = strdup("../"); while ((de = readdir(d)) != NULL) { int name_len = strlen(de->d_name); if (de->d_type == DT_DIR) { // skip "." and ".." entries if (name_len == 1 && de->d_name[0] == '.') continue; if (name_len == 2 && de->d_name[0] == '.' && de->d_name[1] == '.') continue; if (d_size >= d_alloc) { d_alloc *= 2; dirs = (char**)realloc(dirs, d_alloc * sizeof(char*)); } dirs[d_size] = (char*)malloc(name_len + 2); strcpy(dirs[d_size], de->d_name); dirs[d_size][name_len] = '/'; dirs[d_size][name_len+1] = '\0'; ++d_size; } else if (de->d_type == DT_REG && name_len >= 4 && strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) { if (z_size >= z_alloc) { z_alloc *= 2; zips = (char**)realloc(zips, z_alloc * sizeof(char*)); } zips[z_size++] = strdup(de->d_name); } } closedir(d); qsort(dirs, d_size, sizeof(char*), compare_string); qsort(zips, z_size, sizeof(char*), compare_string); // append dirs to the zips list if (d_size + z_size + 1 > z_alloc) { z_alloc = d_size + z_size + 1; zips = (char**)realloc(zips, z_alloc * sizeof(char*)); } memcpy(zips + z_size, dirs, d_size * sizeof(char*)); free(dirs); z_size += d_size; zips[z_size] = NULL; int result; int chosen_item = 0; do { chosen_item = get_menu_selection(headers, zips, 1, chosen_item, device); char* item = zips[chosen_item]; int item_len = strlen(item); if (chosen_item == 0) { // item 0 is always "../" // go up but continue browsing (if the caller is update_directory) result = -1; break; } else if (item[item_len-1] == '/') { // recurse down into a subdirectory char new_path[PATH_MAX]; strlcpy(new_path, path, PATH_MAX); 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, device); if (result >= 0) break; } else { // selected a zip file: attempt to install it, and return // the status to the caller. char new_path[PATH_MAX]; strlcpy(new_path, path, PATH_MAX); strlcat(new_path, "/", PATH_MAX); strlcat(new_path, item, PATH_MAX); ui->Print("\n-- Install %s ...\n", path); set_sdcard_update_bootloader_message(); char* copy = copy_sideloaded_package(new_path); if (unmount_when_done != NULL) { ensure_path_unmounted(unmount_when_done); } if (copy) { result = install_package(copy, wipe_cache, TEMPORARY_INSTALL_FILE); free(copy); } else { result = INSTALL_ERROR; } break; } } while (true); int i; for (i = 0; i < z_size; ++i) free(zips[i]); free(zips); free(headers); if (unmount_when_done != NULL) { ensure_path_unmounted(unmount_when_done); } return result; }
int sdcard_directory(const char* path) { ensure_path_mounted(SDCARD_ROOT); const char* MENU_HEADERS[] = { "Choose a package to install:", path, NULL }; DIR* d; struct dirent* de; d = opendir(path); if (d == NULL) { LOGE("error opening %s: %s\n", path, strerror(errno)); ensure_path_unmounted(SDCARD_ROOT); return 0; } char** headers = prepend_title(MENU_HEADERS); int s_size = 0; int s_alloc = 10; char** sele = malloc(s_alloc * sizeof(char*)); int d_size = 0; int d_alloc = 10; char** dirs = malloc(d_alloc * sizeof(char*)); int z_size = 0; int z_alloc = 10; char** zips = malloc(z_alloc * sizeof(char*)); if (get_new_zip_dir == 1) { sele[0] = strdup("[SELECT CURRENT FOLDER]"); s_size++; } sele[s_size] = strdup("../"); inc_menu_loc(s_size); s_size++; while ((de = readdir(d)) != NULL) { int name_len = strlen(de->d_name); if (de->d_type == DT_DIR) { // skip "." and ".." entries if (name_len == 1 && de->d_name[0] == '.') continue; if (name_len == 2 && de->d_name[0] == '.' && de->d_name[1] == '.') continue; if (d_size >= d_alloc) { d_alloc *= 2; dirs = realloc(dirs, d_alloc * sizeof(char*)); } dirs[d_size] = malloc(name_len + 2); strcpy(dirs[d_size], de->d_name); dirs[d_size][name_len] = '/'; dirs[d_size][name_len+1] = '\0'; ++d_size; } else if (de->d_type == DT_REG && name_len >= 4 && strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) { if (z_size >= z_alloc) { z_alloc *= 2; zips = realloc(zips, z_alloc * sizeof(char*)); } zips[z_size++] = strdup(de->d_name); } } closedir(d); notError = 0; qsort(dirs, d_size, sizeof(char*), compare_string); qsort(zips, z_size, sizeof(char*), compare_string); // append dirs to the zips list if (d_size + z_size + 1 > z_alloc) { z_alloc = d_size + z_size + 1; zips = realloc(zips, z_alloc * sizeof(char*)); } memcpy(zips + z_size, dirs, d_size * sizeof(char*)); free(dirs); z_size += d_size; zips[z_size] = NULL; if (z_size + s_size + 1 > s_alloc) { s_alloc = z_size + s_size + 1; sele = realloc(sele, s_alloc * sizeof(char*)); } memcpy(sele + s_size, zips, z_size * sizeof(char*)); s_size += z_size; sele[s_size] = NULL; int result; int chosen_item = 0; do { chosen_item = get_menu_selection(headers, sele, 1, chosen_item); char* item = sele[chosen_item]; int item_len = strlen(item); if (chosen_item == 0) { // item 0 is always "../" // go up but continue browsing (if the caller is sdcard_directory) if (get_new_zip_dir == 1) { strcpy(tw_zip_location_val,path); write_s_file(); return 1; } else { dec_menu_loc(); result = -1; break; } } else if (chosen_item == 1 && get_new_zip_dir == 1) { dec_menu_loc(); result = -1; break; } else if (item[item_len-1] == '/') { // recurse down into a subdirectory char new_path[PATH_MAX]; strlcpy(new_path, path, PATH_MAX); strlcat(new_path, "/", PATH_MAX); strlcat(new_path, item, PATH_MAX); new_path[strlen(new_path)-1] = '\0'; // truncate the trailing '/' result = sdcard_directory(new_path); if (go_home) { notError = 1; dec_menu_loc(); if (get_new_zip_dir == 1) { return 1; } else { return 0; } } if (result >= 0) break; } else { if (get_new_zip_dir != 1) { // selected a zip file: attempt to install it, and return // the status to the caller. char new_path[PATH_MAX]; strlcpy(new_path, path, PATH_MAX); strlcat(new_path, "/", PATH_MAX); strlcat(new_path, item, PATH_MAX); ui_print("\n-- Install %s ...\n", path); set_sdcard_update_bootloader_message(); char* copy = copy_sideloaded_package(new_path); ensure_path_unmounted(SDCARD_ROOT); if (copy) { result = install_package(copy); free(copy); } else { result = INSTALL_ERROR; } break; } } } while (true); free(zips); free(sele); free(headers); //ensure_path_unmounted(SDCARD_ROOT); return result; }
// Return REBOOT, SHUTDOWN, or REBOOT_BOOTLOADER. Returning NO_ACTION // means to take the default, which is to reboot or shutdown depending // on if the --shutdown_after flag was passed to recovery. static Device::BuiltinAction prompt_and_wait(Device* device, int status) { const char* const* headers = prepend_title(device->GetMenuHeaders()); for (;;) { finish_recovery(NULL); switch (status) { case INSTALL_SUCCESS: case INSTALL_NONE: ui->SetBackground(RecoveryUI::NO_COMMAND); break; case INSTALL_ERROR: case INSTALL_CORRUPT: ui->SetBackground(RecoveryUI::ERROR); break; } ui->SetProgressType(RecoveryUI::EMPTY); 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. Device::BuiltinAction chosen_action = device->InvokeMenuItem(chosen_item); int wipe_cache = 0; switch (chosen_action) { case Device::NO_ACTION: break; case Device::REBOOT: case Device::SHUTDOWN: case Device::REBOOT_BOOTLOADER: return chosen_action; case Device::WIPE_DATA: wipe_data(ui->IsTextVisible(), device); if (!ui->IsTextVisible()) return Device::NO_ACTION; break; case Device::WIPE_CACHE: ui->Print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui->Print("Cache wipe complete.\n"); if (!ui->IsTextVisible()) return Device::NO_ACTION; break; case Device::APPLY_EXT: { ensure_path_mounted(SDCARD_ROOT); char* path = browse_directory(SDCARD_ROOT, device); if (path == NULL) { ui->Print("\n-- No package file selected.\n", path); break; } ui->Print("\n-- Install %s ...\n", path); set_sdcard_update_bootloader_message(); void* token = start_sdcard_fuse(path); int status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache, TEMPORARY_INSTALL_FILE, false); finish_sdcard_fuse(token); ensure_path_unmounted(SDCARD_ROOT); if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (!ui->IsTextVisible()) { return Device::NO_ACTION; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); } } break; } case Device::APPLY_CACHE: ui->Print("\nAPPLY_CACHE is deprecated.\n"); break; case Device::READ_RECOVERY_LASTLOG: choose_recovery_file(device); break; case Device::APPLY_ADB_SIDELOAD: status = apply_from_adb(ui, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); copy_logs(); } else if (!ui->IsTextVisible()) { return Device::NO_ACTION; // reboot if logs aren't visible } else { ui->Print("\nInstall from ADB complete.\n"); } } break; } } }
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; } } }
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; } } }