From cfb63ae2b11dc5b9a7e0231a489131523114e7de Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Wed, 19 Sep 2012 14:30:17 -0400 Subject: Improve adb sideload -- add cancel Also copy zip from /tmp to storage and remove from /tmp to prevent running out of RAM. --- adb_install.cpp | 16 +++++++++- gui/action.cpp | 34 +++++++++++++++++--- gui/devices/800x1280/res/ui.xml | 70 +++++++++++++++++++++++++++++++++++++++-- recovery.cpp | 7 +++-- 4 files changed, 116 insertions(+), 11 deletions(-) diff --git a/adb_install.cpp b/adb_install.cpp index 12bce1cca..f5ba89c3f 100644 --- a/adb_install.cpp +++ b/adb_install.cpp @@ -33,6 +33,7 @@ extern "C" { #include "minadbd/adb.h" #include "twinstall.h" +#include "data.h" int TWinstall_zip(const char* path, int* wipe_cache); } @@ -86,6 +87,7 @@ apply_from_adb(RecoveryUI* ui_, int* wipe_cache, const char* install_file) { execl("/sbin/recovery", "recovery", "--adbd", NULL); _exit(-1); } + DataManager_SetIntValue("tw_child_pid", child); 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 @@ -108,5 +110,17 @@ apply_from_adb(RecoveryUI* ui_, int* wipe_cache, const char* install_file) { } return INSTALL_ERROR; } - return TWinstall_zip(ADB_SIDELOAD_FILENAME, wipe_cache); + char zip_file[255]; + if (strncmp(ADB_SIDELOAD_FILENAME, "/tmp", 4) == 0) { + char command[255]; + sprintf(zip_file, "%s/%s", DataManager_GetCurrentStoragePath(), "sideload.zip"); + ui->Print("Copying zip to '%s'\n", zip_file); + sprintf(command, "cp %s %s", ADB_SIDELOAD_FILENAME, zip_file); + system(command); + sprintf(command, "rm %s", ADB_SIDELOAD_FILENAME); + system(command); + } else { + strcpy(zip_file, ADB_SIDELOAD_FILENAME); + } + return TWinstall_zip(zip_file, wipe_cache); } diff --git a/gui/action.cpp b/gui/action.cpp index 5118b4c29..4114bf0aa 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -1057,16 +1057,42 @@ LOGE("TODO: Implement ORS support\n"); simulate_progress_bar(); } else { int wipe_cache = 0; + string Command; + + if (!PartitionManager.Mount_Current_Storage(true)) { + operation_end(1, simulate); + return 0; + } + if (TWFunc::Path_Exists(ADB_SIDELOAD_FILENAME)) { + Command = "rm "; + Command += ADB_SIDELOAD_FILENAME; + system(Command.c_str()); + } + Command = "touch "; + Command += ADB_SIDELOAD_FILENAME; + system(Command.c_str()); ui_print("Starting ADB sideload feature...\n"); - system("touch /tmp/update.zip"); - ret = apply_from_adb(ui, &wipe_cache, "/tmp/last_install"); - LOGI("Result was: %i\n", ret); + ret = apply_from_adb(ui, &wipe_cache, "/tmp/install_log"); if (ret != 0) - ret = 1; + ret = 1; // failure + else if (wipe_cache) + PartitionManager.Wipe_By_Path("/cache"); } operation_end(ret, simulate); return 0; } + if (function == "adbsideloadcancel") + { + int child_pid; + string Command; + Command = "rm "; + Command += ADB_SIDELOAD_FILENAME; + system(Command.c_str()); + DataManager::GetValue("tw_child_pid", child_pid); + ui_print("Cancelling ADB sideload...\n"); + kill(child_pid, SIGTERM); + return 0; + } } else { diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml index decfcad55..a131e8969 100755 --- a/gui/devices/800x1280/res/ui.xml +++ b/gui/devices/800x1280/res/ui.xml @@ -67,7 +67,7 @@ - + @@ -909,6 +909,69 @@ + + + + + + + %tw_action_text1% + + + + + + %tw_action_text2% + + + + + + Cancel + + + + + + + + + + + + + + + action_complete + + + + + + + + + + action_complete + + + + + + + %tw_action_param% + + + + + + + %tw_action_param% + %tw_action2_param% + + + + @@ -2546,12 +2609,13 @@ ADB Sideload + tw_back=advanced tw_action=adbsideload tw_action_text1=ADB Sideload tw_action_text2=Usage: adb sideload filename.zip tw_complete_text1=ADB Sideload Complete - tw_slider_text=Swipe to Wipe - action_page + tw_cancel_function=adbsideloadcancel + action_page_cancel diff --git a/recovery.cpp b/recovery.cpp index b333db904..b8bb09920 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -773,6 +773,10 @@ print_property(const char *key, const char *name, void *cookie) { int main(int argc, char **argv) { + // Recovery needs to install world-readable files, so clear umask + // set by init + umask(0); + time_t start = time(NULL); // If these fail, there's not really anywhere to complain... @@ -792,9 +796,6 @@ main(int argc, char **argv) { } printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&start)); - // Recovery needs to install world-readable files, so clear umask - // set by init - umask(0); Device* device = make_device(); ui = device->GetUI(); -- cgit v1.2.3