blob: 954f3f5abe7e8eb09f59bd8aed448e9bd54ee0f0 [file] [log] [blame]
bigbiffdf8436b2020-08-30 16:22:34 -04001/*
bigbiffaed1bdf2021-08-03 18:21:39 -04002 Copyright 2012-2021 TeamWin
bigbiffdf8436b2020-08-30 16:22:34 -04003 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
21void 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++) {
bigbiffaed1bdf2021-08-03 18:21:39 -040027 if (!processRecoveryArgs(args, index))
28 break;
29 }
30 printf("\n");
31}
32
33bool startupArgs::processRecoveryArgs(std::vector<std::string> args, int index) {
DarthJabba958d1e7a2020-10-23 14:44:08 +010034 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
bigbiffdf8436b2020-08-30 16:22:34 -040044 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);
Ctapchuk452489e2021-11-12 21:34:05 +070054 } else if (args[index].find(UPDATE_PACKAGE) != std::string::npos || args[index].find(SPECIAL_UPDATE_PACKAGE) != std::string::npos) {
bigbiffdf8436b2020-08-30 16:22:34 -040055 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;
sekaiacg0df7c9e2021-12-04 20:14:33 +080061 SkipDecryption = arg.find("@") == 0;
bigbiffdf8436b2020-08-30 16:22:34 -040062 if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
bigbiffaed1bdf2021-08-03 18:21:39 -040063 return false;
bigbiffdf8436b2020-08-30 16:22:34 -040064 }
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"))
bigbiffaed1bdf2021-08-03 18:21:39 -040075 return false;
bigbiffdf8436b2020-08-30 16:22:34 -040076 } else if (args[index].find(WIPE_CACHE) != std::string::npos) {
77 if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
bigbiffaed1bdf2021-08-03 18:21:39 -040078 return false;
bigbiffdf8436b2020-08-30 16:22:34 -040079 } 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"))
bigbiffaed1bdf2021-08-03 18:21:39 -040082 return false;
bigbiffdf8436b2020-08-30 16:22:34 -040083 }
bigbiffaed1bdf2021-08-03 18:21:39 -040084 return true;
bigbiffdf8436b2020-08-30 16:22:34 -040085}
86
87bool startupArgs::Should_Skip_Decryption() {
88 return SkipDecryption;
89}
90
91std::string startupArgs::Get_Intent() {
92 return Send_Intent;
93}
94
95bool startupArgs::Get_Fastboot_Mode() {
96 return fastboot_mode;
DarthJabba933d8fd32020-10-23 14:23:26 +010097}