bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 1 | /* |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 2 | Copyright 2012-2021 TeamWin |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "startupArgs.hpp" |
| 20 | |
| 21 | void startupArgs::parse(int *argc, char ***argv) { |
| 22 | std::vector<std::string> args = args::get_args(argc, argv); |
| 23 | int index; |
| 24 | |
| 25 | LOGINFO("Startup Commands: "); |
| 26 | for (index = 1; index < args.size(); index++) { |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 27 | if (!processRecoveryArgs(args, index)) |
| 28 | break; |
| 29 | } |
| 30 | printf("\n"); |
| 31 | } |
| 32 | |
| 33 | bool startupArgs::processRecoveryArgs(std::vector<std::string> args, int index) { |
DarthJabba9 | 58d1e7a | 2020-10-23 14:44:08 +0100 | [diff] [blame] | 34 | if (args[index].find(RESCUE_PARTY) != std::string::npos) { |
| 35 | gui_print("\n\n"); |
| 36 | gui_msg(Msg(msg::kError, "rescue_party0=Android Rescue Party trigger! Possible solutions? Either:")); |
| 37 | gui_msg(Msg(msg::kError, "rescue_party1= 1. Wipe caches, and/or")); |
| 38 | gui_msg(Msg(msg::kError, "rescue_party2= 2. Format data, and/or")); |
| 39 | gui_msg(Msg(msg::kError, "rescue_party3= 3. Clean-flash your ROM.")); |
| 40 | gui_print(" \n"); |
| 41 | gui_msg(Msg(msg::kError, "rescue_party4=The reported problem is:")); |
| 42 | gui_print_color("error", " '%s'\n\n", args[index+1].c_str()); |
| 43 | } else |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 44 | printf("'%s'", args[index].c_str()); |
| 45 | if (args[index] == FASTBOOT) { |
| 46 | fastboot_mode = true; |
| 47 | android::base::SetProperty("sys.usb.config", "none"); |
| 48 | android::base::SetProperty("sys.usb.configfs", "0"); |
| 49 | sleep(1); |
| 50 | android::base::SetProperty("sys.usb.configfs", "1"); |
| 51 | android::base::SetProperty("sys.usb.config", "fastboot"); |
| 52 | DataManager::SetValue("tw_enable_adb", 0); |
| 53 | DataManager::SetValue("tw_enable_fastboot", 1); |
Ctapchuk | 452489e | 2021-11-12 21:34:05 +0700 | [diff] [blame] | 54 | } else if (args[index].find(UPDATE_PACKAGE) != std::string::npos || args[index].find(SPECIAL_UPDATE_PACKAGE) != std::string::npos) { |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 55 | std::string::size_type eq_pos = args[index].find("="); |
| 56 | std::string arg = args[index].substr(eq_pos + 1, args[index].size()); |
| 57 | if (arg.size() == 0) { |
| 58 | LOGERR("argument error specifying zip file\n"); |
| 59 | } else { |
| 60 | std::string ORSCommand = "install " + arg; |
sekaiacg | 0df7c9e | 2021-12-04 20:14:33 +0800 | [diff] [blame] | 61 | SkipDecryption = arg.find("@") == 0; |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 62 | if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand)) |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 63 | return false; |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 64 | } |
| 65 | } else if (args[index].find(SEND_INTENT) != std::string::npos) { |
| 66 | std::string::size_type eq_pos = args[index].find("="); |
| 67 | std::string arg = args[index].substr(eq_pos + 1, args[index].size()); |
| 68 | if (arg.size() == 0) { |
| 69 | LOGERR("argument error specifying intent file\n"); |
| 70 | } else { |
| 71 | Send_Intent = arg; |
| 72 | } |
| 73 | } else if (args[index].find(WIPE_DATA) != std::string::npos) { |
| 74 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n")) |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 75 | return false; |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 76 | } else if (args[index].find(WIPE_CACHE) != std::string::npos) { |
| 77 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n")) |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 78 | return false; |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 79 | } else if (args[index].find(NANDROID) != std::string::npos) { |
| 80 | DataManager::SetValue(TW_BACKUP_NAME, gui_parse_text("{@auto_generate}")); |
| 81 | if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n")) |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 82 | return false; |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 83 | } |
bigbiff | aed1bdf | 2021-08-03 18:21:39 -0400 | [diff] [blame] | 84 | return true; |
bigbiff | df8436b | 2020-08-30 16:22:34 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | bool startupArgs::Should_Skip_Decryption() { |
| 88 | return SkipDecryption; |
| 89 | } |
| 90 | |
| 91 | std::string startupArgs::Get_Intent() { |
| 92 | return Send_Intent; |
| 93 | } |
| 94 | |
| 95 | bool startupArgs::Get_Fastboot_Mode() { |
| 96 | return fastboot_mode; |
DarthJabba9 | 33d8fd3 | 2020-10-23 14:23:26 +0100 | [diff] [blame] | 97 | } |