blob: 5109914769380ac9506dc138d4b2eef5c5f7f7bb [file] [log] [blame]
Dees_Troya449a6f2013-04-07 17:50:11 -05001/*
bigbiffdf8436b2020-08-30 16:22:34 -04002 Copyright 2012-2020 TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
Dees_Troya449a6f2013-04-07 17:50:11 -05004
bigbiffdf8436b2020-08-30 16:22:34 -04005 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.
Dees_Troya449a6f2013-04-07 17:50:11 -05009
bigbiffdf8436b2020-08-30 16:22:34 -040010 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/>.
Dees_Troya449a6f2013-04-07 17:50:11 -050017*/
18
19#include <stdio.h>
20#include <stdlib.h>
Ethan Yonker74db1572015-10-28 12:44:49 -050021#include <string>
Dees_Troya449a6f2013-04-07 17:50:11 -050022#include <sys/stat.h>
23#include <sys/types.h>
24#include <time.h>
25#include <unistd.h>
Ethan Yonkerf9f99bc2014-12-29 09:10:34 -060026#include <signal.h>
Ethan Yonker74db1572015-10-28 12:44:49 -050027#include "gui/twmsg.h"
Dees_Troya449a6f2013-04-07 17:50:11 -050028
29#include "cutils/properties.h"
Dees_Troya449a6f2013-04-07 17:50:11 -050030
31#ifdef ANDROID_RB_RESTART
32#include "cutils/android_reboot.h"
33#else
34#include <sys/reboot.h>
35#endif
36
37extern "C" {
38#include "gui/gui.h"
39}
Ethan Yonkerf1179622016-08-25 15:32:21 -050040#include "set_metadata.h"
Ethan Yonker74db1572015-10-28 12:44:49 -050041#include "gui/gui.hpp"
42#include "gui/pages.hpp"
43#include "gui/objects.hpp"
Dees_Troya449a6f2013-04-07 17:50:11 -050044#include "twcommon.h"
45#include "twrp-functions.hpp"
46#include "data.hpp"
bigbiff22851b92021-09-01 16:46:57 -040047#include "kernel_module_loader.hpp"
Dees_Troya449a6f2013-04-07 17:50:11 -050048#include "partitions.hpp"
Mohd Faraz0d9a62e2020-02-20 00:10:26 +053049#ifdef __ANDROID_API_N__
50#include <android-base/strings.h>
51#else
52#include <base/strings.h>
53#endif
Dees_Troya449a6f2013-04-07 17:50:11 -050054#include "openrecoveryscript.hpp"
55#include "variables.h"
bigbiffdf8436b2020-08-30 16:22:34 -040056#include "startupArgs.hpp"
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -040057#include "twrpAdbBuFifo.hpp"
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050058#ifdef TW_USE_NEW_MINADBD
bigbiffd58ba182020-03-23 10:02:29 -040059// #include "minadbd/minadbd.h"
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050060#else
61extern "C" {
Ethan Yonker84d61ce2017-05-10 16:11:35 -050062#include "minadbd21/adb.h"
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050063}
64#endif
Dees_Troya449a6f2013-04-07 17:50:11 -050065
Ethan Yonker8373cfe2017-09-08 06:50:54 -050066//extern int adb_server_main(int is_daemon, int server_port, int /* reply_fd */);
Ethan Yonker534d4e02016-08-26 10:05:03 -050067
Dees_Troya449a6f2013-04-07 17:50:11 -050068TWPartitionManager PartitionManager;
69int Log_Offset;
Ethan Yonker6277c792014-09-15 14:54:30 -050070bool datamedia;
Dees_Troya449a6f2013-04-07 17:50:11 -050071
72static void Print_Prop(const char *key, const char *name, void *cookie) {
73 printf("%s=%s\n", key, name);
74}
75
bigbiff7ba75002020-04-11 20:47:09 -040076static void Decrypt_Page(bool SkipDecryption, bool datamedia) {
77 // Offer to decrypt if the device is encrypted
78 if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) {
79 if (SkipDecryption) {
80 LOGINFO("Skipping decryption\n");
Captain Throwback89b56a12021-02-10 18:25:07 -050081 PartitionManager.Update_System_Details();
Mohd Faraz815e2402020-09-19 19:31:52 +053082 } else if (DataManager::GetIntValue(TW_CRYPTO_PWTYPE) != 0) {
bigbiff7ba75002020-04-11 20:47:09 -040083 LOGINFO("Is encrypted, do decrypt page first\n");
Mohd Faraze3948ec2020-08-14 01:40:59 +000084 if (DataManager::GetIntValue(TW_IS_FBE))
85 DataManager::SetValue("tw_crypto_user_id", "0");
bigbiff7ba75002020-04-11 20:47:09 -040086 if (gui_startPage("decrypt", 1, 1) != 0) {
87 LOGERR("Failed to start decrypt GUI page.\n");
bigbiff7ba75002020-04-11 20:47:09 -040088 }
89 }
90 } else if (datamedia) {
Captain Throwback89b56a12021-02-10 18:25:07 -050091 PartitionManager.Update_System_Details();
bigbiff7ba75002020-04-11 20:47:09 -040092 if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
93 LOGINFO("Failed to get default contexts and file mode for storage files.\n");
94 } else {
95 LOGINFO("Got default contexts and file mode for storage files.\n");
96 }
97 }
98}
99
bigbiff22851b92021-09-01 16:46:57 -0400100static void process_fastbootd_mode() {
101 LOGINFO("starting fastboot\n");
102 printf("=> Linking mtab\n");
103 symlink("/proc/mounts", "/etc/mtab");
104 std::string fstab_filename = "/etc/twrp.fstab";
105 if (!TWFunc::Path_Exists(fstab_filename)) {
106 fstab_filename = "/etc/recovery.fstab";
107 }
108 printf("=> Processing %s\n", fstab_filename.c_str());
109 if (!PartitionManager.Process_Fstab(fstab_filename, 1, false)) {
110 LOGERR("Failing out of recovery due to problem with fstab.\n");
111 return;
112 }
113 TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor");
114 PartitionManager.Setup_Super_Devices();
115 PartitionManager.Prepare_Super_Volume(ven);
116#ifdef TW_LOAD_VENDOR_MODULES
bigbiff850fa282021-10-09 12:37:29 -0400117 KernelModuleLoader::Load_Vendor_Modules();
118 if (android::base::GetBoolProperty("ro.virtual_ab.enabled", false)) {
119 PartitionManager.Unmap_Super_Devices();
120 }
bigbiff22851b92021-09-01 16:46:57 -0400121#endif
bigbiff850fa282021-10-09 12:37:29 -0400122
bigbiff22851b92021-09-01 16:46:57 -0400123 gui_msg(Msg("fastboot_console_msg=Entered Fastboot mode..."));
124 if (gui_startPage("fastboot", 1, 1) != 0) {
125 LOGERR("Failed to start fastbootd page.\n");
126 }
127}
128
bigbiffdf8436b2020-08-30 16:22:34 -0400129static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decryption) {
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200130 char crash_prop_val[PROPERTY_VALUE_MAX];
131 int crash_counter;
bigbiff22851b92021-09-01 16:46:57 -0400132 std::string cmdline;
133 if (TWFunc::read_file("/proc/cmdline", cmdline) != 0) {
134 LOGINFO("Unable to read cmdline for fastboot mode\n");
135 }
136
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200137 property_get("twrp.crash_counter", crash_prop_val, "-1");
138 crash_counter = atoi(crash_prop_val) + 1;
139 snprintf(crash_prop_val, sizeof(crash_prop_val), "%d", crash_counter);
140 property_set("twrp.crash_counter", crash_prop_val);
141
bigbiffdf8436b2020-08-30 16:22:34 -0400142 if (crash_counter == 0) {
143 property_list(Print_Prop, NULL);
144 printf("\n");
145 } else {
146 printf("twrp.crash_counter=%d\n", crash_counter);
147 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500148
Dees_Troya449a6f2013-04-07 17:50:11 -0500149 printf("=> Linking mtab\n");
150 symlink("/proc/mounts", "/etc/mtab");
Ethan Yonker53273ec2018-03-09 11:22:54 -0600151 std::string fstab_filename = "/etc/twrp.fstab";
152 if (!TWFunc::Path_Exists(fstab_filename)) {
153 fstab_filename = "/etc/recovery.fstab";
Dees_Troy329383e2013-08-29 14:16:06 +0000154 }
Ethan Yonker53273ec2018-03-09 11:22:54 -0600155 printf("=> Processing %s\n", fstab_filename.c_str());
bigbiff22851b92021-09-01 16:46:57 -0400156 if (!PartitionManager.Process_Fstab(fstab_filename, 1, true)) {
Ethan Yonker53273ec2018-03-09 11:22:54 -0600157 LOGERR("Failing out of recovery due to problem with fstab.\n");
bigbiffdf8436b2020-08-30 16:22:34 -0400158 return;
Dees_Troya449a6f2013-04-07 17:50:11 -0500159 }
bigbiffee7b7ff2020-03-23 15:08:27 -0400160
bigbiff22851b92021-09-01 16:46:57 -0400161#ifdef TW_LOAD_VENDOR_MODULES
162 bool fastboot_mode = cmdline.find("twrpfastboot=1") != std::string::npos;
163 if (fastboot_mode)
bigbiff850fa282021-10-09 12:37:29 -0400164 KernelModuleLoader::Load_Vendor_Modules();
bigbiff22851b92021-09-01 16:46:57 -0400165 else
bigbiff850fa282021-10-09 12:37:29 -0400166 KernelModuleLoader::Load_Vendor_Modules();
bigbiff22851b92021-09-01 16:46:57 -0400167#endif
168
Captain Throwbackdc0823c2020-09-06 13:07:23 -0400169// We are doing this here to allow super partition to be set up prior to overriding properties
170#if defined(TW_INCLUDE_LIBRESETPROP) && defined(TW_OVERRIDE_SYSTEM_PROPS)
171 if (!PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
172 LOGERR("Unable to mount %s\n", PartitionManager.Get_Android_Root_Path().c_str());
173 } else {
174 stringstream override_props(EXPAND(TW_OVERRIDE_SYSTEM_PROPS));
175 string current_prop;
176 while (getline(override_props, current_prop, ';')) {
177 string other_prop;
178 if (current_prop.find("=") != string::npos) {
179 other_prop = current_prop.substr(current_prop.find("=") + 1);
180 current_prop = current_prop.substr(0, current_prop.find("="));
181 } else {
182 other_prop = current_prop;
183 }
184 other_prop = android::base::Trim(other_prop);
185 current_prop = android::base::Trim(current_prop);
186 string sys_val = TWFunc::System_Property_Get(other_prop, PartitionManager, PartitionManager.Get_Android_Root_Path().c_str());
187 if (!sys_val.empty()) {
188 LOGINFO("Overriding %s with value: \"%s\" from system property %s\n", current_prop.c_str(), sys_val.c_str(), other_prop.c_str());
189 int error = TWFunc::Property_Override(current_prop, sys_val);
190 if (error) {
191 LOGERR("Failed overriding property %s, error_code: %d\n", current_prop.c_str(), error);
192 }
193 } else {
194 LOGINFO("Not overriding %s with empty value from system property %s\n", current_prop.c_str(), other_prop.c_str());
195 }
196 }
197 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
198 }
199#endif
200
Dees_Troya449a6f2013-04-07 17:50:11 -0500201 // Check for and run startup script if script exists
bigbiffad58e1b2020-07-06 20:24:34 -0400202 TWFunc::check_and_run_script("/system/bin/runatboot.sh", "boot");
203 TWFunc::check_and_run_script("/system/bin/postrecoveryboot.sh", "boot");
Dees_Troya449a6f2013-04-07 17:50:11 -0500204
205#ifdef TW_INCLUDE_INJECTTWRP
206 // Back up TWRP Ramdisk if needed:
207 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
Dees_Troya449a6f2013-04-07 17:50:11 -0500208 LOGINFO("Backing up TWRP ramdisk...\n");
209 if (Boot == NULL || Boot->Current_File_System != "emmc")
Vojtech Bocek05534202013-09-11 08:11:56 +0200210 TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
Dees_Troya449a6f2013-04-07 17:50:11 -0500211 else {
212 string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
Vojtech Bocek05534202013-09-11 08:11:56 +0200213 TWFunc::Exec_Cmd(injectcmd);
Dees_Troya449a6f2013-04-07 17:50:11 -0500214 }
215 LOGINFO("Backup of TWRP ramdisk done.\n");
216#endif
217
bigbiffdf8436b2020-08-30 16:22:34 -0400218 Decrypt_Page(skip_decryption, datamedia);
bigbiff83298f52021-10-13 19:24:42 -0400219 // Check for and load custom theme if present
220 TWFunc::check_selinux_support();
221 gui_loadCustomResources();
Captain Throwback89b56a12021-02-10 18:25:07 -0500222 PartitionManager.Output_Partition_Logging();
Dees_Troya449a6f2013-04-07 17:50:11 -0500223
Vojtech Bocek2005a842014-03-11 19:40:34 +0100224 // Fixup the RTC clock on devices which require it
bigbiffadc599e2020-05-28 19:36:30 +0000225 if (crash_counter == 0)
226 TWFunc::Fixup_Time_On_Boot();
Vojtech Bocek2005a842014-03-11 19:40:34 +0100227
epicXa721f952021-01-04 13:01:31 +0530228 DataManager::LoadTWRPFolderInfo();
Ian Macdonald1e0474a2020-09-09 02:43:13 +0200229 DataManager::ReadSettingsFile();
bigbiff bigbiff19874f12019-01-08 20:06:57 -0500230
Dees_Troya449a6f2013-04-07 17:50:11 -0500231 // Run any outstanding OpenRecoveryScript
bigbiff25d25b92020-06-19 16:07:38 -0400232 std::string cacheDir = TWFunc::get_log_dir();
233 if (cacheDir == DATA_LOGS_DIR)
234 cacheDir = "/data/cache";
bigbiff bigbiff19874f12019-01-08 20:06:57 -0500235 std::string orsFile = cacheDir + "/recovery/openrecoveryscript";
bigbiffdf8436b2020-08-30 16:22:34 -0400236 if ((DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 || skip_decryption) && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(orsFile))) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500237 OpenRecoveryScript::Run_OpenRecoveryScript();
238 }
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100239
Ethan Yonker6f49e112014-09-03 21:42:49 -0500240#ifdef TW_HAS_MTP
Ethan Yonker6f49e112014-09-03 21:42:49 -0500241 char mtp_crash_check[PROPERTY_VALUE_MAX];
242 property_get("mtp.crash_check", mtp_crash_check, "0");
Matt Mower653a1702017-02-16 10:38:52 -0600243 if (DataManager::GetIntValue("tw_mtp_enabled")
244 && !strcmp(mtp_crash_check, "0") && !crash_counter
245 && (!DataManager::GetIntValue(TW_IS_ENCRYPTED) || DataManager::GetIntValue(TW_IS_DECRYPTED))) {
Ethan Yonker6f49e112014-09-03 21:42:49 -0500246 property_set("mtp.crash_check", "1");
Matt Mower653a1702017-02-16 10:38:52 -0600247 LOGINFO("Starting MTP\n");
248 if (!PartitionManager.Enable_MTP())
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600249 PartitionManager.Disable_MTP();
Matt Mower653a1702017-02-16 10:38:52 -0600250 else
251 gui_msg("mtp_enabled=MTP Enabled");
Ethan Yonker6f49e112014-09-03 21:42:49 -0500252 property_set("mtp.crash_check", "0");
Matt Mower653a1702017-02-16 10:38:52 -0600253 } else if (strcmp(mtp_crash_check, "0")) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500254 gui_warn("mtp_crash=MTP Crashed, not starting MTP on boot.");
Ethan Yonker12055fa2014-09-04 08:06:53 -0500255 DataManager::SetValue("tw_mtp_enabled", 0);
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600256 PartitionManager.Disable_MTP();
Matt Mower653a1702017-02-16 10:38:52 -0600257 } else if (crash_counter == 1) {
258 LOGINFO("TWRP crashed; disabling MTP as a precaution.\n");
259 PartitionManager.Disable_MTP();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400260 }
Ethan Yonker6f49e112014-09-03 21:42:49 -0500261#endif
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400262
Ethan Yonker89583ef2015-08-26 09:01:59 -0500263#ifndef TW_OEM_BUILD
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500264 // Check if system has never been changed
Captain Throwback9d6feb52018-07-27 10:05:24 -0400265 TWPartition* sys = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500266 TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor");
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500267 if (sys) {
bigbiffee7b7ff2020-03-23 15:08:27 -0400268 if (sys->Get_Super_Status()) {
bigbiff7ba75002020-04-11 20:47:09 -0400269#ifdef TW_INCLUDE_CRYPTO
bigbiff25d25b92020-06-19 16:07:38 -0400270 std::string recoveryLogDir(DATA_LOGS_DIR);
271 recoveryLogDir += "/recovery";
272 if (!TWFunc::Path_Exists(recoveryLogDir)) {
273 bool created = PartitionManager.Recreate_Logs_Dir();
274 if (!created)
275 LOGERR("Unable to create log directory for TWRP\n");
276 }
bigbiff7ba75002020-04-11 20:47:09 -0400277 DataManager::ReadSettingsFile();
278#endif
bigbiffee7b7ff2020-03-23 15:08:27 -0400279 } else {
280 if ((DataManager::GetIntValue("tw_mount_system_ro") == 0 && sys->Check_Lifetime_Writes() == 0) || DataManager::GetIntValue("tw_mount_system_ro") == 2) {
281 if (DataManager::GetIntValue("tw_never_show_system_ro_page") == 0) {
282 DataManager::SetValue("tw_back", "main");
283 if (gui_startPage("system_readonly", 1, 1) != 0) {
284 LOGERR("Failed to start system_readonly GUI page.\n");
285 }
286 } else if (DataManager::GetIntValue("tw_mount_system_ro") == 0) {
287 sys->Change_Mount_Read_Only(false);
288 if (ven)
289 ven->Change_Mount_Read_Only(false);
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500290 }
bigbiffee7b7ff2020-03-23 15:08:27 -0400291 } else if (DataManager::GetIntValue("tw_mount_system_ro") == 1) {
292 // Do nothing, user selected to leave system read only
293 } else {
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500294 sys->Change_Mount_Read_Only(false);
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500295 if (ven)
296 ven->Change_Mount_Read_Only(false);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500297 }
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500298 }
299 }
Ethan Yonker89583ef2015-08-26 09:01:59 -0500300#endif
bigbiff7ba75002020-04-11 20:47:09 -0400301
bigbiffaac58612020-08-30 11:18:39 -0400302 TWFunc::Update_Log_File();
303
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -0400304 adb_bu_fifo->threadAdbBuFifo();
305
Ethan Yonker89583ef2015-08-26 09:01:59 -0500306#ifndef TW_OEM_BUILD
Ethan Yonker9132d912015-02-02 10:32:49 -0600307 // Disable flashing of stock recovery
308 TWFunc::Disable_Stock_Recovery_Replace();
Ethan Yonker89583ef2015-08-26 09:01:59 -0500309#endif
bigbiffdf8436b2020-08-30 16:22:34 -0400310}
Dees_Troya449a6f2013-04-07 17:50:11 -0500311
bigbiffdf8436b2020-08-30 16:22:34 -0400312static void reboot() {
Ethan Yonker74db1572015-10-28 12:44:49 -0500313 gui_msg(Msg("rebooting=Rebooting..."));
bigbiffdf8436b2020-08-30 16:22:34 -0400314 TWFunc::Update_Log_File();
Dees_Troya449a6f2013-04-07 17:50:11 -0500315 string Reboot_Arg;
bigbiffdf8436b2020-08-30 16:22:34 -0400316
Dees_Troya449a6f2013-04-07 17:50:11 -0500317 DataManager::GetValue("tw_reboot_arg", Reboot_Arg);
318 if (Reboot_Arg == "recovery")
319 TWFunc::tw_reboot(rb_recovery);
320 else if (Reboot_Arg == "poweroff")
321 TWFunc::tw_reboot(rb_poweroff);
322 else if (Reboot_Arg == "bootloader")
323 TWFunc::tw_reboot(rb_bootloader);
324 else if (Reboot_Arg == "download")
325 TWFunc::tw_reboot(rb_download);
mauronofrioe9a49ef2018-10-03 13:38:16 +0200326 else if (Reboot_Arg == "edl")
327 TWFunc::tw_reboot(rb_edl);
bigbiffdf8436b2020-08-30 16:22:34 -0400328 else if (Reboot_Arg == "fastboot")
329 TWFunc::tw_reboot(rb_fastboot);
Dees_Troya449a6f2013-04-07 17:50:11 -0500330 else
331 TWFunc::tw_reboot(rb_system);
bigbiffdf8436b2020-08-30 16:22:34 -0400332}
333
334int main(int argc, char **argv) {
335 // Recovery needs to install world-readable files, so clear umask
336 // set by init
337 umask(0);
bigbiffdf8436b2020-08-30 16:22:34 -0400338 Log_Offset = 0;
339
340 // Set up temporary log file (/tmp/recovery.log)
341 freopen(TMP_LOG_FILE, "a", stdout);
342 setbuf(stdout, NULL);
343 freopen(TMP_LOG_FILE, "a", stderr);
344 setbuf(stderr, NULL);
345
346 signal(SIGPIPE, SIG_IGN);
347
348 // Handle ADB sideload
349 if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
350 property_set("ctl.stop", "adbd");
351#ifdef TW_USE_NEW_MINADBD
352 //adb_server_main(0, DEFAULT_ADB_PORT, -1); TODO fix this for android8
353 // minadbd_main();
354#else
355 adb_main(argv[2]);
356#endif
357 return 0;
358 }
359
360#ifdef RECOVERY_SDCARD_ON_DATA
361 datamedia = true;
362#endif
363
364 property_set("ro.twrp.boot", "1");
365 property_set("ro.twrp.version", TW_VERSION_STR);
366
367 time_t StartupTime = time(NULL);
368 printf("Starting TWRP %s-%s on %s (pid %d)\n", TW_VERSION_STR, TW_GIT_REVISION, ctime(&StartupTime), getpid());
369
370 // Load default values to set DataManager constants and handle ifdefs
371 DataManager::SetDefaultValues();
372 printf("Starting the UI...\n");
373 gui_init();
374
375 // Load up all the resources
376 gui_loadResources();
377
bigbiffdf8436b2020-08-30 16:22:34 -0400378 startupArgs startup;
379 startup.parse(&argc, &argv);
380 twrpAdbBuFifo *adb_bu_fifo = new twrpAdbBuFifo();
381 TWFunc::Clear_Bootloader_Message();
382
383 if (startup.Get_Fastboot_Mode()) {
bigbiff22851b92021-09-01 16:46:57 -0400384 process_fastbootd_mode();
bigbiffdf8436b2020-08-30 16:22:34 -0400385 delete adb_bu_fifo;
386 TWFunc::Update_Intent_File(startup.Get_Intent());
bigbiffdf8436b2020-08-30 16:22:34 -0400387 reboot();
388 return 0;
389 } else {
390 process_recovery_mode(adb_bu_fifo, startup.Should_Skip_Decryption());
391 }
392
Ian Macdonalda9910222020-10-27 18:02:21 +0100393 PageManager::LoadLanguage(DataManager::GetStrValue("tw_language"));
394 GUIConsole::Translate_Now();
395
epicX271bb3a2020-12-30 01:03:18 +0530396 TWFunc::checkforapp(); //Checking compatibility for TWRP app
397
bigbiffdf8436b2020-08-30 16:22:34 -0400398 // Launch the main GUI
399 gui_start();
400 delete adb_bu_fifo;
401 TWFunc::Update_Intent_File(startup.Get_Intent());
bigbiffdf8436b2020-08-30 16:22:34 -0400402 reboot();
Dees_Troya449a6f2013-04-07 17:50:11 -0500403
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200404 return 0;
Dees_Troya449a6f2013-04-07 17:50:11 -0500405}