From 03a42f6c6afc69919544c6dbe0fce49637ec17df Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Fri, 8 Aug 2014 11:03:51 -0500 Subject: Add command line capabilities Allows sending openrecoveryscript commands to TWRP via shell. This may be handy for visually impaired users, for various one click utilities to drive TWRP commands from a computer, for using TWRP when a catastrophic hardware failure like a shattered screen prevents you from being able to use touch, or even on devices like a TV stick where touch and USB mouse input is unavailable. This patch also includes a few minor changes to openrecoveryscript including proper support for rebooting via the script and for decrypting the device via the command line. Change-Id: I796ad168efdd2da9c25334ac93d1079daaa7b0bc --- openrecoveryscript.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'openrecoveryscript.cpp') diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp index 014702741..1461f2d88 100644 --- a/openrecoveryscript.cpp +++ b/openrecoveryscript.cpp @@ -60,6 +60,20 @@ int OpenRecoveryScript::check_for_script_file(void) { return 0; } +int OpenRecoveryScript::copy_script_file(string filename) { + if (TWFunc::Path_Exists(filename)) { + LOGINFO("Script file found: '%s'\n", filename.c_str()); + if (filename == SCRIPT_FILE_TMP) + return 1; // file is already in the right place + // Copy script file to /tmp + TWFunc::copy_file(filename, SCRIPT_FILE_TMP, 0755); + // Delete the old file + unlink(filename.c_str()); + return 1; + } + return 0; +} + int OpenRecoveryScript::run_script_file(void) { FILE *fp = fopen(SCRIPT_FILE_TMP, "r"); int ret_val = 0, cindex, line_len, i, remove_nl, install_cmd = 0, sideload = 0; @@ -305,7 +319,16 @@ int OpenRecoveryScript::run_script_file(void) { ret_val = 1; } } else if (strcmp(command, "reboot") == 0) { - // Reboot + if (strlen(value) && strcmp(value, "recovery") == 0) + TWFunc::tw_reboot(rb_recovery); + else if (strlen(value) && strcmp(value, "poweroff") == 0) + TWFunc::tw_reboot(rb_poweroff); + else if (strlen(value) && strcmp(value, "bootloader") == 0) + TWFunc::tw_reboot(rb_bootloader); + else if (strlen(value) && strcmp(value, "download") == 0) + TWFunc::tw_reboot(rb_download); + else + TWFunc::tw_reboot(rb_system); } else if (strcmp(command, "cmd") == 0) { DataManager::SetValue("tw_action_text2", "Running Command"); if (cindex != 0) { @@ -350,6 +373,15 @@ int OpenRecoveryScript::run_script_file(void) { ret_val = PartitionManager.Fix_Permissions(); if (ret_val != 0) ret_val = 1; // failure + } else if (strcmp(command, "decrypt") == 0) { + if (*value) { + ret_val = PartitionManager.Decrypt_Device(value); + if (ret_val != 0) + ret_val = 1; // failure + } else { + LOGERR("No password provided.\n"); + ret_val = 1; // failure + } } else { LOGERR("Unrecognized script command: '%s'\n", command); ret_val = 1; -- cgit v1.2.3