blob: 4fe6ec0cd72334bfa8339cd81b78ee605b7e50ef [file] [log] [blame]
bigbiffdf8436b2020-08-30 16:22:34 -04001/*
2 Copyright 2012-2020 TeamWin
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
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++) {
DarthJabba958d1e7a2020-10-23 14:44:08 +010027 if (args[index].find(RESCUE_PARTY) != std::string::npos) {
28 gui_print("\n\n");
29 gui_msg(Msg(msg::kError, "rescue_party0=Android Rescue Party trigger! Possible solutions? Either:"));
30 gui_msg(Msg(msg::kError, "rescue_party1= 1. Wipe caches, and/or"));
31 gui_msg(Msg(msg::kError, "rescue_party2= 2. Format data, and/or"));
32 gui_msg(Msg(msg::kError, "rescue_party3= 3. Clean-flash your ROM."));
33 gui_print(" \n");
34 gui_msg(Msg(msg::kError, "rescue_party4=The reported problem is:"));
35 gui_print_color("error", " '%s'\n\n", args[index+1].c_str());
36 } else
bigbiffdf8436b2020-08-30 16:22:34 -040037 printf("'%s'", args[index].c_str());
38 if (args[index] == FASTBOOT) {
39 fastboot_mode = true;
40 android::base::SetProperty("sys.usb.config", "none");
41 android::base::SetProperty("sys.usb.configfs", "0");
42 sleep(1);
43 android::base::SetProperty("sys.usb.configfs", "1");
44 android::base::SetProperty("sys.usb.config", "fastboot");
45 DataManager::SetValue("tw_enable_adb", 0);
46 DataManager::SetValue("tw_enable_fastboot", 1);
DarthJabba933d8fd32020-10-23 14:23:26 +010047 } else if (args[index].find(UPDATE_PACKAGE) != std::string::npos) {
bigbiffdf8436b2020-08-30 16:22:34 -040048 std::string::size_type eq_pos = args[index].find("=");
49 std::string arg = args[index].substr(eq_pos + 1, args[index].size());
50 if (arg.size() == 0) {
51 LOGERR("argument error specifying zip file\n");
52 } else {
53 std::string ORSCommand = "install " + arg;
54 SkipDecryption = arg.find("@") == 1;
55 if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
56 break;
57 }
58 } else if (args[index].find(SEND_INTENT) != std::string::npos) {
59 std::string::size_type eq_pos = args[index].find("=");
60 std::string arg = args[index].substr(eq_pos + 1, args[index].size());
61 if (arg.size() == 0) {
62 LOGERR("argument error specifying intent file\n");
63 } else {
64 Send_Intent = arg;
65 }
66 } else if (args[index].find(WIPE_DATA) != std::string::npos) {
67 if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
68 break;
69 } else if (args[index].find(WIPE_CACHE) != std::string::npos) {
70 if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
71 break;
72 } else if (args[index].find(NANDROID) != std::string::npos) {
73 DataManager::SetValue(TW_BACKUP_NAME, gui_parse_text("{@auto_generate}"));
74 if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
75 break;
76 }
77 }
78 printf("\n");
79}
80
81bool startupArgs::Should_Skip_Decryption() {
82 return SkipDecryption;
83}
84
85std::string startupArgs::Get_Intent() {
86 return Send_Intent;
87}
88
89bool startupArgs::Get_Fastboot_Mode() {
90 return fastboot_mode;
DarthJabba933d8fd32020-10-23 14:23:26 +010091}