From 24e7eb73cea323c959c93cbe3130774a97b3c501 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Sat, 3 Jan 2015 16:13:06 -0600 Subject: Thread openrecoveryscript action to properly display action page The action page fails to display properly during ORS processing unless we thread the ORS action. Based upon the work done in this patch set by _that: https://gerrit.omnirom.org/#/c/11226 Change-Id: I6dac790ac26d9b3a02df778516fea011d67aea70 --- gui/action.cpp | 60 ++++++++++++++++++++++++++++++++++++--------------------- gui/objects.hpp | 1 + 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/gui/action.cpp b/gui/action.cpp index 361a676b2..ef325aa4f 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -1378,34 +1378,50 @@ int GUIAction::adbsideloadcancel(std::string arg) return 0; } +void* GUIAction::openrecoveryscript_thread_fn(void *cookie) +{ + GUIAction* this_ = (GUIAction*) cookie; + + // Check for the SCRIPT_FILE_TMP first as these are AOSP recovery commands + // that we converted to ORS commands during boot in recovery.cpp. + // Run those first. + int reboot = 0; + if (TWFunc::Path_Exists(SCRIPT_FILE_TMP)) { + gui_print("Processing AOSP recovery commands...\n"); + if (OpenRecoveryScript::run_script_file() == 0) { + reboot = 1; + } + } + // Check for the ORS file in /cache and attempt to run those commands. + if (OpenRecoveryScript::check_for_script_file()) { + gui_print("Processing OpenRecoveryScript file...\n"); + if (OpenRecoveryScript::run_script_file() == 0) { + reboot = 1; + } + } + if (reboot) { + usleep(2000000); // Sleep for 2 seconds before rebooting + TWFunc::tw_reboot(rb_system); + } else { + DataManager::SetValue("tw_page_done", 1); + } + this_->operation_end(1); + return NULL; +} + int GUIAction::openrecoveryscript(std::string arg) { operation_start("OpenRecoveryScript"); if (simulate) { simulate_progress_bar(); + operation_end(0); } else { - // Check for the SCRIPT_FILE_TMP first as these are AOSP recovery commands - // that we converted to ORS commands during boot in recovery.cpp. - // Run those first. - int reboot = 0; - if (TWFunc::Path_Exists(SCRIPT_FILE_TMP)) { - gui_print("Processing AOSP recovery commands...\n"); - if (OpenRecoveryScript::run_script_file() == 0) { - reboot = 1; - } - } - // Check for the ORS file in /cache and attempt to run those commands. - if (OpenRecoveryScript::check_for_script_file()) { - gui_print("Processing OpenRecoveryScript file...\n"); - if (OpenRecoveryScript::run_script_file() == 0) { - reboot = 1; - } - } - if (reboot) { - usleep(2000000); // Sleep for 2 seconds before rebooting - TWFunc::tw_reboot(rb_system); - } else { - DataManager::SetValue("tw_page_done", 1); + // we need to start a thread to allow the action page to display properly + pthread_t openrecoveryscript_thread; + int rc = pthread_create(&openrecoveryscript_thread, NULL, openrecoveryscript_thread_fn, this); + if (rc != 0) { + LOGERR("Error starting sideload thread, rc=%i.\n", rc); + operation_end(1); } } return 0; diff --git a/gui/objects.hpp b/gui/objects.hpp index bf07c86bc..124c9264d 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -288,6 +288,7 @@ protected: void operation_end(const int operation_status); static void* command_thread(void *cookie); static void* sideload_thread_fn(void *cookie); + static void* openrecoveryscript_thread_fn(void *cookie); time_t Start; // map action name to function pointer -- cgit v1.2.3