summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--adb_install.cpp51
-rw-r--r--adb_install.h2
-rw-r--r--gui/action.cpp58
-rw-r--r--minadbd/usb_linux_client.c2
-rw-r--r--twinstall.cpp18
5 files changed, 79 insertions, 52 deletions
diff --git a/adb_install.cpp b/adb_install.cpp
index c731d1cd2..77b9a8c1c 100644
--- a/adb_install.cpp
+++ b/adb_install.cpp
@@ -36,7 +36,7 @@ extern "C" {
static RecoveryUI* ui = NULL;
-static void
+void
set_usb_driver(bool enabled) {
int fd = open("/sys/class/android_usb/android0/enable", O_WRONLY);
if (fd < 0) {
@@ -68,7 +68,7 @@ stop_adbd() {
}
-static void
+void
maybe_restart_adbd() {
char value[PROPERTY_VALUE_MAX+1];
int len = property_get("ro.debuggable", value, NULL);
@@ -128,12 +128,14 @@ apply_from_adb(const char* install_file) {
break;
}
}
- printf("FIX ME: need to make adb sideload actually install the file!\n");
- //result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false);
+ property_set("tw_sideload_file", FUSE_SIDELOAD_HOST_PATHNAME);
+ // Install is handled elsewhere in TWRP
+ result = 5; //install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false);
break;
}
- if (!waited) {
+ // We do this elsewhere in TWRP
+ /*if (!waited) {
// Calling stat() on this magic filename signals the minadbd
// subprocess to shut down.
stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
@@ -143,25 +145,26 @@ apply_from_adb(const char* install_file) {
// 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");
- } else if (!WIFSIGNALED(status)) {
- printf("status %d\n", WEXITSTATUS(status));
- }
- }
- set_usb_driver(false);
- maybe_restart_adbd();
-
- if (stat(install_file, &st) != 0) {
- if (errno == ENOENT) {
- printf("No package received.\n");
- } else {
- printf("Error reading package:\n %s\n", strerror(errno));
+ if (result != 5) {
+ stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
+ waitpid(child, &status, 0);
+ result = -1;
+ 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));
+ }
}
- return -1;
- }
- return 0;
+ set_usb_driver(false);
+ maybe_restart_adbd();
+ return result;
+ } else {
+ return 0;
+ }
+
+ return -1; // This should not happen
}
diff --git a/adb_install.h b/adb_install.h
index a7cb33686..604c61d27 100644
--- a/adb_install.h
+++ b/adb_install.h
@@ -19,6 +19,8 @@
//class RecoveryUI;
+void set_usb_driver(bool enabled);
+void maybe_restart_adbd();
int apply_from_adb(const char* install_file);
#endif
diff --git a/gui/action.cpp b/gui/action.cpp
index 612e99026..6b8565aed 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -51,6 +51,7 @@ extern "C" {
#include "../twinstall.h"
#include "cutils/properties.h"
#include "../minadbd/adb.h"
+#include "../adb_install.h"
int TWinstall_zip(const char* path, int* wipe_cache);
void run_script(const char *str1, const char *str2, const char *str3, const char *str4, const char *str5, const char *str6, const char *str7, int request_confirm);
@@ -1257,30 +1258,42 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
} else {
int wipe_cache = 0;
int wipe_dalvik = 0;
- string Sideload_File;
- if (!PartitionManager.Mount_Current_Storage(false)) {
- gui_print("Using RAM for sideload storage.\n");
- Sideload_File = "/tmp/sideload.zip";
- } else {
- Sideload_File = DataManager::GetCurrentStoragePath() + "/sideload.zip";
- }
- if (TWFunc::Path_Exists(Sideload_File)) {
- unlink(Sideload_File.c_str());
- }
gui_print("Starting ADB sideload feature...\n");
DataManager::GetValue("tw_wipe_dalvik", wipe_dalvik);
- ret = apply_from_adb(Sideload_File.c_str());
+ ret = apply_from_adb("/");
DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start
+ char file_prop[PROPERTY_VALUE_MAX];
+ property_get("tw_sideload_file", file_prop, "error");
if (ret != 0) {
ret = 1; // failure
- } else if (TWinstall_zip(Sideload_File.c_str(), &wipe_cache) == 0) {
- if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache"))
- PartitionManager.Wipe_By_Path("/cache");
- if (wipe_dalvik)
- PartitionManager.Wipe_Dalvik_Cache();
+ if (ret == -2)
+ gui_print("You need adb 1.0.32 or newer to sideload to this device.\n");
} else {
- ret = 1; // failure
+ if (TWinstall_zip(file_prop, &wipe_cache) == 0) {
+ if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache"))
+ PartitionManager.Wipe_By_Path("/cache");
+ if (wipe_dalvik)
+ PartitionManager.Wipe_Dalvik_Cache();
+ } else {
+ ret = 1; // failure
+ }
+ set_usb_driver(false);
+ maybe_restart_adbd();
+ }
+ if (strcmp(file_prop, "error") != 0) {
+ struct stat st;
+ stat("/sideload/exit", &st);
+ int child_pid, status;
+ char child_prop[PROPERTY_VALUE_MAX];
+ property_get("tw_child_pid", child_prop, "error");
+ if (strcmp(child_prop, "error") == 0) {
+ LOGERR("Unable to get child ID from prop\n");
+ } else {
+ child_pid = atoi(child_prop);
+ LOGINFO("Waiting for child sideload process to exit.\n");
+ waitpid(child_pid, &status, 0);
+ }
}
if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
operation_start("ReinjectTWRP");
@@ -1304,18 +1317,19 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
}
if (function == "adbsideloadcancel")
{
- int child_pid;
+ int child_pid, status;
char child_prop[PROPERTY_VALUE_MAX];
- string Sideload_File;
- Sideload_File = DataManager::GetCurrentStoragePath() + "/sideload.zip";
- unlink(Sideload_File.c_str());
+ struct stat st;
+ DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui
+ gui_print("Cancelling ADB sideload...\n");
+ stat("/sideload/exit", &st);
+ sleep(1);
property_get("tw_child_pid", child_prop, "error");
if (strcmp(child_prop, "error") == 0) {
LOGERR("Unable to get child ID from prop\n");
return 0;
}
child_pid = atoi(child_prop);
- gui_print("Cancelling ADB sideload...\n");
kill(child_pid, SIGTERM);
DataManager::SetValue("tw_page_done", "1"); // For OpenRecoveryScript support
return 0;
diff --git a/minadbd/usb_linux_client.c b/minadbd/usb_linux_client.c
index 29bab1558..ec32bcf91 100644
--- a/minadbd/usb_linux_client.c
+++ b/minadbd/usb_linux_client.c
@@ -256,7 +256,7 @@ static void usb_adb_init()
close_on_exec(fd);
}
- D("[ usb_init - starting thread ]\n");
+ printf("[ usb_init - starting thread ]\n");
if(adb_thread_create(&tid, usb_adb_open_thread, h)){
fatal_errno("cannot create usb thread");
fprintf(stderr, "cannot create the usb thread()\n");
diff --git a/twinstall.cpp b/twinstall.cpp
index 595c4d2a6..4e478d408 100644
--- a/twinstall.cpp
+++ b/twinstall.cpp
@@ -257,14 +257,22 @@ extern "C" int TWinstall_zip(const char* path, int* wipe_cache) {
string strpath = path;
ZipArchive Zip;
- gui_print("Installing '%s'...\nChecking for MD5 file...\n", path);
- md5sum.setfn(strpath);
- md5_return = md5sum.verify_md5digest();
- if (md5_return == -2) { // md5 did not match
- LOGERR("Aborting zip install\n");
+ if (strcmp(path, "error") == 0) {
+ LOGERR("Failed to get adb sideload file: '%s'\n", path);
return INSTALL_CORRUPT;
}
+ gui_print("Installing '%s'...\n", path);
+ if (strlen(path) < 9 || strncmp(path, "/sideload", 9) != 0) {
+ gui_print("Checking for MD5 file...\n");
+ md5sum.setfn(strpath);
+ md5_return = md5sum.verify_md5digest();
+ if (md5_return == -2) { // md5 did not match
+ LOGERR("Aborting zip install\n");
+ return INSTALL_CORRUPT;
+ }
+ }
+
#ifndef TW_OEM_BUILD
DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
#endif