blob: 01b1955dcb010c2787e978d823304a4d59112a31 [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++) {
27 printf("'%s'", args[index].c_str());
28 if (args[index] == FASTBOOT) {
29 fastboot_mode = true;
30 android::base::SetProperty("sys.usb.config", "none");
31 android::base::SetProperty("sys.usb.configfs", "0");
32 sleep(1);
33 android::base::SetProperty("sys.usb.configfs", "1");
34 android::base::SetProperty("sys.usb.config", "fastboot");
35 DataManager::SetValue("tw_enable_adb", 0);
36 DataManager::SetValue("tw_enable_fastboot", 1);
37 } else if (args[index] == UPDATE_PACKAGE) {
38 std::string::size_type eq_pos = args[index].find("=");
39 std::string arg = args[index].substr(eq_pos + 1, args[index].size());
40 if (arg.size() == 0) {
41 LOGERR("argument error specifying zip file\n");
42 } else {
43 std::string ORSCommand = "install " + arg;
44 SkipDecryption = arg.find("@") == 1;
45 if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
46 break;
47 }
48 } else if (args[index].find(SEND_INTENT) != std::string::npos) {
49 std::string::size_type eq_pos = args[index].find("=");
50 std::string arg = args[index].substr(eq_pos + 1, args[index].size());
51 if (arg.size() == 0) {
52 LOGERR("argument error specifying intent file\n");
53 } else {
54 Send_Intent = arg;
55 }
56 } else if (args[index].find(WIPE_DATA) != std::string::npos) {
57 if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
58 break;
59 } else if (args[index].find(WIPE_CACHE) != std::string::npos) {
60 if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
61 break;
62 } else if (args[index].find(NANDROID) != std::string::npos) {
63 DataManager::SetValue(TW_BACKUP_NAME, gui_parse_text("{@auto_generate}"));
64 if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
65 break;
66 }
67 }
68 printf("\n");
69}
70
71bool startupArgs::Should_Skip_Decryption() {
72 return SkipDecryption;
73}
74
75std::string startupArgs::Get_Intent() {
76 return Send_Intent;
77}
78
79bool startupArgs::Get_Fastboot_Mode() {
80 return fastboot_mode;
81}