blob: b33a6ad1a091bb13ed347d7452f87b029fe18cae [file] [log] [blame]
Dees_Troya449a6f2013-04-07 17:50:11 -05001/*
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05002 TWRP is free software: you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation, either version 3 of the License, or
5 (at your option) any later version.
Dees_Troya449a6f2013-04-07 17:50:11 -05006
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05007 TWRP is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
Dees_Troya449a6f2013-04-07 17:50:11 -050011
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050012 You should have received a copy of the GNU General Public License
13 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
Dees_Troya449a6f2013-04-07 17:50:11 -050014*/
15
16#include <stdio.h>
17#include <stdlib.h>
Ethan Yonker74db1572015-10-28 12:44:49 -050018#include <string>
Dees_Troya449a6f2013-04-07 17:50:11 -050019#include <sys/stat.h>
20#include <sys/types.h>
21#include <time.h>
22#include <unistd.h>
Ethan Yonkerf9f99bc2014-12-29 09:10:34 -060023#include <signal.h>
Ethan Yonker74db1572015-10-28 12:44:49 -050024#include "gui/twmsg.h"
Dees_Troya449a6f2013-04-07 17:50:11 -050025
26#include "cutils/properties.h"
27extern "C" {
Dees_Troya449a6f2013-04-07 17:50:11 -050028#include "bootloader.h"
29}
30
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"
Ethan Yonker4b94cfd2014-12-11 10:00:45 -060039#include "set_metadata.h"
Dees_Troya449a6f2013-04-07 17:50:11 -050040}
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"
47#include "partitions.hpp"
48#include "openrecoveryscript.hpp"
49#include "variables.h"
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050050#include "twrpDU.hpp"
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050051#ifdef TW_USE_NEW_MINADBD
52#include "adb.h"
53#else
54extern "C" {
55#include "minadbd.old/adb.h"
56}
57#endif
Dees_Troya449a6f2013-04-07 17:50:11 -050058
Dees_Troya95f55c2013-08-17 13:14:43 +000059#ifdef HAVE_SELINUX
60#include "selinux/label.h"
61struct selabel_handle *selinux_handle;
62#endif
63
Dees_Troya449a6f2013-04-07 17:50:11 -050064TWPartitionManager PartitionManager;
65int Log_Offset;
Ethan Yonker6277c792014-09-15 14:54:30 -050066bool datamedia;
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050067twrpDU du;
Dees_Troya449a6f2013-04-07 17:50:11 -050068
69static void Print_Prop(const char *key, const char *name, void *cookie) {
70 printf("%s=%s\n", key, name);
71}
72
73int main(int argc, char **argv) {
74 // Recovery needs to install world-readable files, so clear umask
75 // set by init
76 umask(0);
77
78 Log_Offset = 0;
79
80 // Set up temporary log file (/tmp/recovery.log)
81 freopen(TMP_LOG_FILE, "a", stdout);
82 setbuf(stdout, NULL);
83 freopen(TMP_LOG_FILE, "a", stderr);
84 setbuf(stderr, NULL);
85
Ethan Yonkerf9f99bc2014-12-29 09:10:34 -060086 signal(SIGPIPE, SIG_IGN);
87
Dees_Troya449a6f2013-04-07 17:50:11 -050088 // Handle ADB sideload
89 if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
thatcc8ddca2015-01-03 01:59:36 +010090 property_set("ctl.stop", "adbd");
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050091#ifdef TW_USE_NEW_MINADBD
92 adb_main(0, DEFAULT_ADB_PORT);
93#else
Dees_Troya449a6f2013-04-07 17:50:11 -050094 adb_main(argv[2]);
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050095#endif
Dees_Troya449a6f2013-04-07 17:50:11 -050096 return 0;
97 }
98
Ethan Yonker6277c792014-09-15 14:54:30 -050099#ifdef RECOVERY_SDCARD_ON_DATA
100 datamedia = true;
101#endif
102
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200103 char crash_prop_val[PROPERTY_VALUE_MAX];
104 int crash_counter;
105 property_get("twrp.crash_counter", crash_prop_val, "-1");
106 crash_counter = atoi(crash_prop_val) + 1;
107 snprintf(crash_prop_val, sizeof(crash_prop_val), "%d", crash_counter);
108 property_set("twrp.crash_counter", crash_prop_val);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400109 property_set("ro.twrp.boot", "1");
110 property_set("ro.twrp.version", TW_VERSION_STR);
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200111
Dees_Troya449a6f2013-04-07 17:50:11 -0500112 time_t StartupTime = time(NULL);
thatcc8ddca2015-01-03 01:59:36 +0100113 printf("Starting TWRP %s on %s (pid %d)\n", TW_VERSION_STR, ctime(&StartupTime), getpid());
Dees_Troya449a6f2013-04-07 17:50:11 -0500114
115 // Load default values to set DataManager constants and handle ifdefs
116 DataManager::SetDefaultValues();
117 printf("Starting the UI...");
118 gui_init();
119 printf("=> Linking mtab\n");
120 symlink("/proc/mounts", "/etc/mtab");
Dees_Troy329383e2013-08-29 14:16:06 +0000121 if (TWFunc::Path_Exists("/etc/twrp.fstab")) {
122 if (TWFunc::Path_Exists("/etc/recovery.fstab")) {
123 printf("Renaming regular /etc/recovery.fstab -> /etc/recovery.fstab.bak\n");
124 rename("/etc/recovery.fstab", "/etc/recovery.fstab.bak");
125 }
126 printf("Moving /etc/twrp.fstab -> /etc/recovery.fstab\n");
127 rename("/etc/twrp.fstab", "/etc/recovery.fstab");
128 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500129 printf("=> Processing recovery.fstab\n");
130 if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) {
131 LOGERR("Failing out of recovery due to problem with recovery.fstab.\n");
132 return -1;
133 }
134 PartitionManager.Output_Partition_Logging();
135 // Load up all the resources
136 gui_loadResources();
137
Dees_Troya95f55c2013-08-17 13:14:43 +0000138#ifdef HAVE_SELINUX
bigbiff bigbiffc49d7062013-10-11 20:28:00 -0400139 if (TWFunc::Path_Exists("/prebuilt_file_contexts")) {
140 if (TWFunc::Path_Exists("/file_contexts")) {
141 printf("Renaming regular /file_contexts -> /file_contexts.bak\n");
142 rename("/file_contexts", "/file_contexts.bak");
143 }
144 printf("Moving /prebuilt_file_contexts -> /file_contexts\n");
145 rename("/prebuilt_file_contexts", "/file_contexts");
146 }
Dees_Troya95f55c2013-08-17 13:14:43 +0000147 struct selinux_opt selinux_options[] = {
148 { SELABEL_OPT_PATH, "/file_contexts" }
149 };
bigbiff bigbiffc49d7062013-10-11 20:28:00 -0400150 selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
Dees_Troya95f55c2013-08-17 13:14:43 +0000151 if (!selinux_handle)
152 printf("No file contexts for SELinux\n");
153 else
154 printf("SELinux contexts loaded from /file_contexts\n");
Dees Troy995e88c2013-11-26 21:39:14 +0000155 { // Check to ensure SELinux can be supported by the kernel
156 char *contexts = NULL;
Dees Troy8d0eb132013-12-06 16:55:41 +0000157
158 if (PartitionManager.Mount_By_Path("/cache", true) && TWFunc::Path_Exists("/cache/recovery")) {
159 lgetfilecon("/cache/recovery", &contexts);
160 if (!contexts) {
161 lsetfilecon("/cache/recovery", "test");
162 lgetfilecon("/cache/recovery", &contexts);
163 }
164 } else {
165 LOGINFO("Could not check /cache/recovery SELinux contexts, using /sbin/teamwin instead which may be inaccurate.\n");
166 lgetfilecon("/sbin/teamwin", &contexts);
167 }
Dees Troy995e88c2013-11-26 21:39:14 +0000168 if (!contexts) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500169 gui_warn("no_kernel_selinux=Kernel does not have support for reading SELinux contexts.");
Dees Troy995e88c2013-11-26 21:39:14 +0000170 } else {
171 free(contexts);
Ethan Yonker74db1572015-10-28 12:44:49 -0500172 gui_msg("full_selinux=Full SELinux support is present.");
Dees Troy995e88c2013-11-26 21:39:14 +0000173 }
174 }
175#else
Ethan Yonker74db1572015-10-28 12:44:49 -0500176 gui_warn("no_selinux=No SELinux support (no libselinux).");
Dees_Troya95f55c2013-08-17 13:14:43 +0000177#endif
178
Dees_Troya449a6f2013-04-07 17:50:11 -0500179 PartitionManager.Mount_By_Path("/cache", true);
180
181 string Zip_File, Reboot_Value;
Ethan Yonkera1674162014-11-06 08:35:10 -0600182 bool Cache_Wipe = false, Factory_Reset = false, Perform_Backup = false, Shutdown = false;
Dees_Troya449a6f2013-04-07 17:50:11 -0500183
184 {
Dees_Troy1669f892013-09-04 18:35:08 +0000185 TWPartition* misc = PartitionManager.Find_Partition_By_Path("/misc");
186 if (misc != NULL) {
187 if (misc->Current_File_System == "emmc") {
that4e0e3fc2015-04-13 19:52:49 +0200188 set_misc_device("emmc", misc->Actual_Block_Device.c_str());
Dees_Troy1669f892013-09-04 18:35:08 +0000189 } else if (misc->Current_File_System == "mtd") {
that4e0e3fc2015-04-13 19:52:49 +0200190 set_misc_device("mtd", misc->MTD_Name.c_str());
Dees_Troy1669f892013-09-04 18:35:08 +0000191 } else {
192 LOGERR("Unknown file system for /misc\n");
193 }
194 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500195 get_args(&argc, &argv);
196
197 int index, index2, len;
198 char* argptr;
199 char* ptr;
200 printf("Startup Commands: ");
201 for (index = 1; index < argc; index++) {
202 argptr = argv[index];
203 printf(" '%s'", argv[index]);
204 len = strlen(argv[index]);
205 if (*argptr == '-') {argptr++; len--;}
206 if (*argptr == '-') {argptr++; len--;}
207 if (*argptr == 'u') {
208 ptr = argptr;
209 index2 = 0;
210 while (*ptr != '=' && *ptr != '\n')
211 ptr++;
Kevin Steck7b69e9d2013-10-17 18:24:31 -0400212 // skip the = before grabbing Zip_File
213 while (*ptr == '=')
214 ptr++;
Dees_Troya449a6f2013-04-07 17:50:11 -0500215 if (*ptr) {
216 Zip_File = ptr;
217 } else
218 LOGERR("argument error specifying zip file\n");
219 } else if (*argptr == 'w') {
220 if (len == 9)
221 Factory_Reset = true;
222 else if (len == 10)
223 Cache_Wipe = true;
224 } else if (*argptr == 'n') {
225 Perform_Backup = true;
Ethan Yonkera1674162014-11-06 08:35:10 -0600226 } else if (*argptr == 'p') {
227 Shutdown = true;
Dees_Troya449a6f2013-04-07 17:50:11 -0500228 } else if (*argptr == 's') {
229 ptr = argptr;
230 index2 = 0;
231 while (*ptr != '=' && *ptr != '\n')
232 ptr++;
233 if (*ptr) {
234 Reboot_Value = *ptr;
235 }
236 }
237 }
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200238 printf("\n");
Dees_Troya449a6f2013-04-07 17:50:11 -0500239 }
240
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200241 if(crash_counter == 0) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500242 property_list(Print_Prop, NULL);
243 printf("\n");
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200244 } else {
245 printf("twrp.crash_counter=%d\n", crash_counter);
Dees_Troya449a6f2013-04-07 17:50:11 -0500246 }
247
248 // Check for and run startup script if script exists
249 TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot");
250 TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot");
251
252#ifdef TW_INCLUDE_INJECTTWRP
253 // Back up TWRP Ramdisk if needed:
254 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
Dees_Troya449a6f2013-04-07 17:50:11 -0500255 LOGINFO("Backing up TWRP ramdisk...\n");
256 if (Boot == NULL || Boot->Current_File_System != "emmc")
Vojtech Bocek05534202013-09-11 08:11:56 +0200257 TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
Dees_Troya449a6f2013-04-07 17:50:11 -0500258 else {
259 string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
Vojtech Bocek05534202013-09-11 08:11:56 +0200260 TWFunc::Exec_Cmd(injectcmd);
Dees_Troya449a6f2013-04-07 17:50:11 -0500261 }
262 LOGINFO("Backup of TWRP ramdisk done.\n");
263#endif
264
265 bool Keep_Going = true;
266 if (Perform_Backup) {
Dees Troyb21cc642013-09-10 17:36:41 +0000267 DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)");
Dees_Troya449a6f2013-04-07 17:50:11 -0500268 if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
269 Keep_Going = false;
270 }
271 if (Keep_Going && !Zip_File.empty()) {
272 string ORSCommand = "install " + Zip_File;
273
274 if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
275 Keep_Going = false;
276 }
277 if (Keep_Going) {
278 if (Factory_Reset) {
279 if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
280 Keep_Going = false;
281 } else if (Cache_Wipe) {
282 if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
283 Keep_Going = false;
284 }
285 }
286
287 TWFunc::Update_Log_File();
288 // Offer to decrypt if the device is encrypted
289 if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) {
290 LOGINFO("Is encrypted, do decrypt page first\n");
Ethan Yonkerfd0439e2015-01-14 11:08:13 -0600291 if (gui_startPage("decrypt", 1, 1) != 0) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500292 LOGERR("Failed to start decrypt GUI page.\n");
Ethan Yonkercf50da52015-01-12 21:59:07 -0600293 } else {
294 // Check for and load custom theme if present
295 gui_loadCustomResources();
Dees_Troya449a6f2013-04-07 17:50:11 -0500296 }
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600297 } else if (datamedia) {
298 if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
Ethan Yonkerd9ff3c52015-01-21 21:51:20 -0600299 LOGINFO("Failed to get default contexts and file mode for storage files.\n");
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600300 } else {
301 LOGINFO("Got default contexts and file mode for storage files.\n");
302 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500303 }
304
305 // Read the settings file
Ethan Yonker73da42c2014-09-03 11:30:33 -0500306#ifdef TW_HAS_MTP
307 // We unmount partitions sometimes during early boot which may override
308 // the default of MTP being enabled by auto toggling MTP off. This
309 // will force it back to enabled then get overridden by the settings
310 // file, assuming that an entry for tw_mtp_enabled is set.
311 DataManager::SetValue("tw_mtp_enabled", 1);
312#endif
Dees_Troya449a6f2013-04-07 17:50:11 -0500313 DataManager::ReadSettingsFile();
Ethan Yonker74db1572015-10-28 12:44:49 -0500314 PageManager::LoadLanguage(DataManager::GetStrValue("tw_language"));
315 GUIConsole::Translate_Now();
Vojtech Bocek2005a842014-03-11 19:40:34 +0100316
317 // Fixup the RTC clock on devices which require it
Vojtech Bocek67351dc2014-07-03 15:22:41 +0200318 if(crash_counter == 0)
319 TWFunc::Fixup_Time_On_Boot();
Vojtech Bocek2005a842014-03-11 19:40:34 +0100320
Dees_Troya449a6f2013-04-07 17:50:11 -0500321 // Run any outstanding OpenRecoveryScript
322 if (DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) {
323 OpenRecoveryScript::Run_OpenRecoveryScript();
324 }
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100325
Ethan Yonker6f49e112014-09-03 21:42:49 -0500326#ifdef TW_HAS_MTP
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400327 // Enable MTP?
Ethan Yonker6f49e112014-09-03 21:42:49 -0500328 char mtp_crash_check[PROPERTY_VALUE_MAX];
329 property_get("mtp.crash_check", mtp_crash_check, "0");
330 if (strcmp(mtp_crash_check, "0") == 0) {
331 property_set("mtp.crash_check", "1");
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600332 if (DataManager::GetIntValue("tw_mtp_enabled") == 1 && ((DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0 && DataManager::GetIntValue(TW_IS_DECRYPTED) != 0) || DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0)) {
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400333 LOGINFO("Enabling MTP during startup\n");
334 if (!PartitionManager.Enable_MTP())
335 PartitionManager.Disable_MTP();
336 else
Ethan Yonker74db1572015-10-28 12:44:49 -0500337 gui_msg("mtp_enabled=MTP Enabled");
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600338 } else {
339 PartitionManager.Disable_MTP();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400340 }
Ethan Yonker6f49e112014-09-03 21:42:49 -0500341 property_set("mtp.crash_check", "0");
342 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500343 gui_warn("mtp_crash=MTP Crashed, not starting MTP on boot.");
Ethan Yonker12055fa2014-09-04 08:06:53 -0500344 DataManager::SetValue("tw_mtp_enabled", 0);
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600345 PartitionManager.Disable_MTP();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400346 }
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600347#else
348 PartitionManager.Disable_MTP();
Ethan Yonker6f49e112014-09-03 21:42:49 -0500349#endif
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400350
Ethan Yonker89583ef2015-08-26 09:01:59 -0500351#ifndef TW_OEM_BUILD
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500352 // Check if system has never been changed
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500353 TWPartition* sys = PartitionManager.Find_Partition_By_Path("/system");
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500354 TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor");
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500355 if (sys) {
Ethan Yonker961d20e2015-06-29 14:00:03 -0500356 if ((DataManager::GetIntValue("tw_mount_system_ro") == 0 && sys->Check_Lifetime_Writes() == 0) || DataManager::GetIntValue("tw_mount_system_ro") == 2) {
357 if (DataManager::GetIntValue("tw_never_show_system_ro_page") == 0) {
358 DataManager::SetValue("tw_back", "main");
359 if (gui_startPage("system_readonly", 1, 1) != 0) {
360 LOGERR("Failed to start system_readonly GUI page.\n");
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500361 }
Ethan Yonker961d20e2015-06-29 14:00:03 -0500362 } else if (DataManager::GetIntValue("tw_mount_system_ro") == 0) {
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500363 sys->Change_Mount_Read_Only(false);
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500364 if (ven)
365 ven->Change_Mount_Read_Only(false);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500366 }
Ethan Yonker961d20e2015-06-29 14:00:03 -0500367 } else if (DataManager::GetIntValue("tw_mount_system_ro") == 1) {
368 // Do nothing, user selected to leave system read only
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500369 } else {
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500370 sys->Change_Mount_Read_Only(false);
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500371 if (ven)
372 ven->Change_Mount_Read_Only(false);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500373 }
374 }
Ethan Yonker89583ef2015-08-26 09:01:59 -0500375#endif
Dees_Troya449a6f2013-04-07 17:50:11 -0500376 // Launch the main GUI
377 gui_start();
378
Ethan Yonker89583ef2015-08-26 09:01:59 -0500379#ifndef TW_OEM_BUILD
Ethan Yonker9132d912015-02-02 10:32:49 -0600380 // Disable flashing of stock recovery
381 TWFunc::Disable_Stock_Recovery_Replace();
Dees_Troya449a6f2013-04-07 17:50:11 -0500382 // Check for su to see if the device is rooted or not
Matt Mower95460192015-11-18 10:31:33 -0600383 if (DataManager::GetIntValue("tw_mount_system_ro") == 0 && PartitionManager.Mount_By_Path("/system", false)) {
Davis Mosenkovsb909aae2015-09-26 13:48:23 -0700384 if (TWFunc::Path_Exists("/supersu/su") && TWFunc::Path_Exists("/system/bin") && !TWFunc::Path_Exists("/system/bin/su") && !TWFunc::Path_Exists("/system/xbin/su") && !TWFunc::Path_Exists("/system/bin/.ext/.su")) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500385 // Device doesn't have su installed
386 DataManager::SetValue("tw_busy", 1);
Ethan Yonkerfd0439e2015-01-14 11:08:13 -0600387 if (gui_startPage("installsu", 1, 1) != 0) {
Dees Troyf193f882013-09-11 14:56:20 +0000388 LOGERR("Failed to start SuperSU install page.\n");
Dees_Troya449a6f2013-04-07 17:50:11 -0500389 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500390 }
391 sync();
392 PartitionManager.UnMount_By_Path("/system", false);
393 }
Ethan Yonker89583ef2015-08-26 09:01:59 -0500394#endif
Dees_Troya449a6f2013-04-07 17:50:11 -0500395
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 // Reboot
Dees_Troya449a6f2013-04-07 17:50:11 -0500397 TWFunc::Update_Intent_File(Reboot_Value);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200398 TWFunc::Update_Log_File();
Ethan Yonker74db1572015-10-28 12:44:49 -0500399 gui_msg(Msg("rebooting=Rebooting..."));
Dees_Troya449a6f2013-04-07 17:50:11 -0500400 string Reboot_Arg;
401 DataManager::GetValue("tw_reboot_arg", Reboot_Arg);
402 if (Reboot_Arg == "recovery")
403 TWFunc::tw_reboot(rb_recovery);
404 else if (Reboot_Arg == "poweroff")
405 TWFunc::tw_reboot(rb_poweroff);
406 else if (Reboot_Arg == "bootloader")
407 TWFunc::tw_reboot(rb_bootloader);
408 else if (Reboot_Arg == "download")
409 TWFunc::tw_reboot(rb_download);
410 else
411 TWFunc::tw_reboot(rb_system);
412
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200413 return 0;
Dees_Troya449a6f2013-04-07 17:50:11 -0500414}