int apply_from_adb() { stop_adbd(); set_usb_driver(1); ui_print("\n\n电脑端刷机开始 ...\n请在电脑上使用如下命令:\n" "\"adb sideload <刷机包路径>\"从电脑刷机...\n\n"); struct sideload_waiter_data data; if ((data.child = fork()) == 0) { execl("/sbin/recovery", "recovery", "adbd", NULL); _exit(-1); } pthread_t sideload_thread; pthread_create(&sideload_thread, NULL, &adb_sideload_thread, &data); static char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "返回取消", NULL }; get_menu_selection(headers, list, 0, 0); set_usb_driver(0); maybe_restart_adbd(); // kill the child kill(data.child, SIGTERM); pthread_join(sideload_thread, NULL); ui_clear_key_queue(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui_print("没有接收到刷机包.\n"); ui_set_background(BACKGROUND_ICON_ERROR); } else { ui_print("读取刷机包失败:\n %s\n", strerror(errno)); ui_set_background(BACKGROUND_ICON_ERROR); } return INSTALL_ERROR; } int install_status = install_package(ADB_SIDELOAD_FILENAME); ui_reset_progress(); if (install_status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("电脑端刷机失败.\n"); } remove(ADB_SIDELOAD_FILENAME); return install_status; }
int apply_from_adb() { stop_adbd(); set_usb_driver(1); ui_print("\n\nSideload started ...\nNow send the package you want to apply\n" "to the device with \"adb sideload <filename>\"...\n\n"); struct sideload_waiter_data data; if ((data.child = fork()) == 0) { execl("/sbin/recovery", "recovery", "adbd", NULL); _exit(-1); } pthread_t sideload_thread; pthread_create(&sideload_thread, NULL, &adb_sideload_thread, &data); static const char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "Cancel sideload", NULL }; get_menu_selection(headers, list, 0, 0); set_usb_driver(0); maybe_restart_adbd(); // kill the child kill(data.child, SIGTERM); pthread_join(sideload_thread, NULL); ui_clear_key_queue(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui_print("No package received.\n"); ui_set_background(BACKGROUND_ICON_ERROR); } else { ui_print("Error reading package:\n %s\n", strerror(errno)); ui_set_background(BACKGROUND_ICON_ERROR); } return INSTALL_ERROR; } int install_status = install_package(ADB_SIDELOAD_FILENAME); ui_reset_progress(); if (install_status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } remove(ADB_SIDELOAD_FILENAME); return install_status; }
int apply_from_adb(const char* install_file) { stop_adbd(); set_usb_driver(true); /* ui->Print("\n\nNow send the package you want to apply\n" "to the device with \"adb sideload <filename>\"...\n"); */ pid_t child; if ((child = fork()) == 0) { execl("/sbin/recovery", "recovery", "--adbd", install_file, NULL); _exit(-1); } char child_prop[PROPERTY_VALUE_MAX]; sprintf(child_prop, "%i", child); property_set("tw_child_pid", child_prop); int status; // TODO(dougz): there should be a way to cancel waiting for a // package (by pushing some button combo on the device). For now // you just have to 'adb sideload' a file that's not a valid // package, like "/dev/null". waitpid(child, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { printf("status %d\n", WEXITSTATUS(status)); } set_usb_driver(false); maybe_restart_adbd(); struct stat st; if (stat(install_file, &st) != 0) { if (errno == ENOENT) { printf("No package received.\n"); } else { printf("Error reading package:\n %s\n", strerror(errno)); } return -1; } return 0; }
int apply_from_adb(RecoveryUI* ui_, int* wipe_cache, const char* install_file) { ui = ui_; stop_adbd(); set_usb_driver(true); ui->Print("\n\nNow send the package you want to apply\n" "to the device with \"adb sideload <filename>\"...\n"); pid_t child; if ((child = fork()) == 0) { execl("/sbin/recovery", "recovery", "--adbd", NULL); _exit(-1); } int status; // TODO(dougz): there should be a way to cancel waiting for a // package (by pushing some button combo on the device). For now // you just have to 'adb sideload' a file that's not a valid // package, like "/dev/null". waitpid(child, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { ui->Print("status %d\n", WEXITSTATUS(status)); } set_usb_driver(false); maybe_restart_adbd(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui->Print("No package received.\n"); } else { ui->Print("Error reading package:\n %s\n", strerror(errno)); } return INSTALL_ERROR; } return install_package(ADB_SIDELOAD_FILENAME, wipe_cache, install_file); }
int apply_from_adb(const char* install_file, pid_t* child_pid) { stop_adbd(); set_usb_driver(true); /* ui->Print("\n\nNow send the package you want to apply\n" "to the device with \"adb sideload <filename>\"...\n"); */ pid_t child; if ((child = fork()) == 0) { execl("/sbin/recovery", "recovery", "--adbd", install_file, NULL); _exit(-1); } *child_pid = child; // caller can now kill the child thread from another thread // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the host // connects and starts serving a package. Poll for its // appearance. (Note that inotify doesn't work with FUSE.) int result; int status; bool waited = false; struct stat st; for (int i = 0; i < ADB_INSTALL_TIMEOUT; ++i) { if (waitpid(child, &status, WNOHANG) != 0) { result = -1; waited = true; break; } if (stat(FUSE_SIDELOAD_HOST_PATHNAME, &st) != 0) { if (errno == ENOENT && i < ADB_INSTALL_TIMEOUT-1) { sleep(1); continue; } else { printf("\nTimed out waiting for package: %s\n\n", strerror(errno)); result = -1; kill(child, SIGKILL); break; } } // Install is handled elsewhere in TWRP //install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false); return 0; } // if we got here, something failed *child_pid = 0; if (!waited) { // Calling stat() on this magic filename signals the minadbd // subprocess to shut down. stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); // TODO(dougz): there should be a way to cancel waiting for a // package (by pushing some button combo on the device). For now // you just have to 'adb sideload' a file that's not a valid // package, like "/dev/null". waitpid(child, &status, 0); } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (WEXITSTATUS(status) == 3) { printf("\nYou need adb 1.0.32 or newer to sideload\nto this device.\n\n"); result = -2; } else if (!WIFSIGNALED(status)) { printf("status %d\n", WEXITSTATUS(status)); } } set_usb_driver(false); maybe_restart_adbd(); return result; }