blob: 3de35af987aa073ab938782f183c786c907fd780 [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"
Dees_Troya449a6f2013-04-07 17:50:11 -050027#include "bootloader.h"
Dees_Troya449a6f2013-04-07 17:50:11 -050028
29#ifdef ANDROID_RB_RESTART
30#include "cutils/android_reboot.h"
31#else
32#include <sys/reboot.h>
33#endif
34
35extern "C" {
36#include "gui/gui.h"
37}
Ethan Yonkerf1179622016-08-25 15:32:21 -050038#include "set_metadata.h"
Ethan Yonker74db1572015-10-28 12:44:49 -050039#include "gui/gui.hpp"
40#include "gui/pages.hpp"
41#include "gui/objects.hpp"
Dees_Troya449a6f2013-04-07 17:50:11 -050042#include "twcommon.h"
43#include "twrp-functions.hpp"
44#include "data.hpp"
45#include "partitions.hpp"
46#include "openrecoveryscript.hpp"
47#include "variables.h"
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050048#include "twrpDU.hpp"
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050049#ifdef TW_USE_NEW_MINADBD
50#include "adb.h"
51#else
52extern "C" {
53#include "minadbd.old/adb.h"
54}
55#endif
Dees_Troya449a6f2013-04-07 17:50:11 -050056
Dees_Troya95f55c2013-08-17 13:14:43 +000057#ifdef HAVE_SELINUX
58#include "selinux/label.h"
59struct selabel_handle *selinux_handle;
60#endif
61
Dees_Troya449a6f2013-04-07 17:50:11 -050062TWPartitionManager PartitionManager;
63int Log_Offset;
Ethan Yonker6277c792014-09-15 14:54:30 -050064bool datamedia;
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050065twrpDU du;
Dees_Troya449a6f2013-04-07 17:50:11 -050066
67static void Print_Prop(const char *key, const char *name, void *cookie) {
68 printf("%s=%s\n", key, name);
69}
70
71int main(int argc, char **argv) {
72 // Recovery needs to install world-readable files, so clear umask
73 // set by init
74 umask(0);
75
76 Log_Offset = 0;
77
78 // Set up temporary log file (/tmp/recovery.log)
79 freopen(TMP_LOG_FILE, "a", stdout);
80 setbuf(stdout, NULL);
81 freopen(TMP_LOG_FILE, "a", stderr);
82 setbuf(stderr, NULL);
83
Ethan Yonkerf9f99bc2014-12-29 09:10:34 -060084 signal(SIGPIPE, SIG_IGN);
85
Dees_Troya449a6f2013-04-07 17:50:11 -050086 // Handle ADB sideload
87 if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
thatcc8ddca2015-01-03 01:59:36 +010088 property_set("ctl.stop", "adbd");
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050089#ifdef TW_USE_NEW_MINADBD
Ethan Yonker34ae4832016-08-24 15:32:18 -050090 adb_server_main(0, DEFAULT_ADB_PORT, -1);
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050091#else
Dees_Troya449a6f2013-04-07 17:50:11 -050092 adb_main(argv[2]);
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050093#endif
Dees_Troya449a6f2013-04-07 17:50:11 -050094 return 0;
95 }
96
Ethan Yonker6277c792014-09-15 14:54:30 -050097#ifdef RECOVERY_SDCARD_ON_DATA
98 datamedia = true;
99#endif
100
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200101 char crash_prop_val[PROPERTY_VALUE_MAX];
102 int crash_counter;
103 property_get("twrp.crash_counter", crash_prop_val, "-1");
104 crash_counter = atoi(crash_prop_val) + 1;
105 snprintf(crash_prop_val, sizeof(crash_prop_val), "%d", crash_counter);
106 property_set("twrp.crash_counter", crash_prop_val);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400107 property_set("ro.twrp.boot", "1");
108 property_set("ro.twrp.version", TW_VERSION_STR);
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200109
Dees_Troya449a6f2013-04-07 17:50:11 -0500110 time_t StartupTime = time(NULL);
that0e2140e2016-08-10 21:04:26 +0200111 printf("Starting TWRP %s-%s on %s (pid %d)\n", TW_VERSION_STR, TW_GIT_REVISION, ctime(&StartupTime), getpid());
Dees_Troya449a6f2013-04-07 17:50:11 -0500112
113 // Load default values to set DataManager constants and handle ifdefs
114 DataManager::SetDefaultValues();
that0e2140e2016-08-10 21:04:26 +0200115 printf("Starting the UI...\n");
Dees_Troya449a6f2013-04-07 17:50:11 -0500116 gui_init();
117 printf("=> Linking mtab\n");
118 symlink("/proc/mounts", "/etc/mtab");
Dees_Troy329383e2013-08-29 14:16:06 +0000119 if (TWFunc::Path_Exists("/etc/twrp.fstab")) {
120 if (TWFunc::Path_Exists("/etc/recovery.fstab")) {
121 printf("Renaming regular /etc/recovery.fstab -> /etc/recovery.fstab.bak\n");
122 rename("/etc/recovery.fstab", "/etc/recovery.fstab.bak");
123 }
124 printf("Moving /etc/twrp.fstab -> /etc/recovery.fstab\n");
125 rename("/etc/twrp.fstab", "/etc/recovery.fstab");
126 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500127 printf("=> Processing recovery.fstab\n");
128 if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) {
129 LOGERR("Failing out of recovery due to problem with recovery.fstab.\n");
130 return -1;
131 }
132 PartitionManager.Output_Partition_Logging();
133 // Load up all the resources
134 gui_loadResources();
135
Dees_Troya95f55c2013-08-17 13:14:43 +0000136#ifdef HAVE_SELINUX
bigbiff bigbiffc49d7062013-10-11 20:28:00 -0400137 if (TWFunc::Path_Exists("/prebuilt_file_contexts")) {
138 if (TWFunc::Path_Exists("/file_contexts")) {
139 printf("Renaming regular /file_contexts -> /file_contexts.bak\n");
140 rename("/file_contexts", "/file_contexts.bak");
141 }
142 printf("Moving /prebuilt_file_contexts -> /file_contexts\n");
143 rename("/prebuilt_file_contexts", "/file_contexts");
144 }
Dees_Troya95f55c2013-08-17 13:14:43 +0000145 struct selinux_opt selinux_options[] = {
146 { SELABEL_OPT_PATH, "/file_contexts" }
147 };
bigbiff bigbiffc49d7062013-10-11 20:28:00 -0400148 selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
Dees_Troya95f55c2013-08-17 13:14:43 +0000149 if (!selinux_handle)
150 printf("No file contexts for SELinux\n");
151 else
152 printf("SELinux contexts loaded from /file_contexts\n");
Dees Troy995e88c2013-11-26 21:39:14 +0000153 { // Check to ensure SELinux can be supported by the kernel
154 char *contexts = NULL;
Dees Troy8d0eb132013-12-06 16:55:41 +0000155
156 if (PartitionManager.Mount_By_Path("/cache", true) && TWFunc::Path_Exists("/cache/recovery")) {
157 lgetfilecon("/cache/recovery", &contexts);
158 if (!contexts) {
159 lsetfilecon("/cache/recovery", "test");
160 lgetfilecon("/cache/recovery", &contexts);
161 }
162 } else {
163 LOGINFO("Could not check /cache/recovery SELinux contexts, using /sbin/teamwin instead which may be inaccurate.\n");
164 lgetfilecon("/sbin/teamwin", &contexts);
165 }
Dees Troy995e88c2013-11-26 21:39:14 +0000166 if (!contexts) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500167 gui_warn("no_kernel_selinux=Kernel does not have support for reading SELinux contexts.");
Dees Troy995e88c2013-11-26 21:39:14 +0000168 } else {
169 free(contexts);
Ethan Yonker74db1572015-10-28 12:44:49 -0500170 gui_msg("full_selinux=Full SELinux support is present.");
Dees Troy995e88c2013-11-26 21:39:14 +0000171 }
172 }
173#else
Ethan Yonker74db1572015-10-28 12:44:49 -0500174 gui_warn("no_selinux=No SELinux support (no libselinux).");
Dees_Troya95f55c2013-08-17 13:14:43 +0000175#endif
176
Dees_Troya449a6f2013-04-07 17:50:11 -0500177 PartitionManager.Mount_By_Path("/cache", true);
178
Ethan Yonker3aa66be2015-12-22 12:30:18 -0600179 string Reboot_Value;
180 bool Shutdown = false;
Dees_Troya449a6f2013-04-07 17:50:11 -0500181
182 {
Dees_Troy1669f892013-09-04 18:35:08 +0000183 TWPartition* misc = PartitionManager.Find_Partition_By_Path("/misc");
184 if (misc != NULL) {
185 if (misc->Current_File_System == "emmc") {
that4e0e3fc2015-04-13 19:52:49 +0200186 set_misc_device("emmc", misc->Actual_Block_Device.c_str());
Dees_Troy1669f892013-09-04 18:35:08 +0000187 } else if (misc->Current_File_System == "mtd") {
that4e0e3fc2015-04-13 19:52:49 +0200188 set_misc_device("mtd", misc->MTD_Name.c_str());
Dees_Troy1669f892013-09-04 18:35:08 +0000189 } else {
190 LOGERR("Unknown file system for /misc\n");
191 }
192 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500193 get_args(&argc, &argv);
194
195 int index, index2, len;
196 char* argptr;
197 char* ptr;
198 printf("Startup Commands: ");
199 for (index = 1; index < argc; index++) {
200 argptr = argv[index];
201 printf(" '%s'", argv[index]);
202 len = strlen(argv[index]);
203 if (*argptr == '-') {argptr++; len--;}
204 if (*argptr == '-') {argptr++; len--;}
205 if (*argptr == 'u') {
206 ptr = argptr;
207 index2 = 0;
208 while (*ptr != '=' && *ptr != '\n')
209 ptr++;
Kevin Steck7b69e9d2013-10-17 18:24:31 -0400210 // skip the = before grabbing Zip_File
211 while (*ptr == '=')
212 ptr++;
Dees_Troya449a6f2013-04-07 17:50:11 -0500213 if (*ptr) {
Ethan Yonker3aa66be2015-12-22 12:30:18 -0600214 string ORSCommand = "install ";
215 ORSCommand.append(ptr);
216
217 if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
218 break;
Dees_Troya449a6f2013-04-07 17:50:11 -0500219 } else
220 LOGERR("argument error specifying zip file\n");
221 } else if (*argptr == 'w') {
Ethan Yonker3aa66be2015-12-22 12:30:18 -0600222 if (len == 9) {
223 if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
224 break;
225 } else if (len == 10) {
226 if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
227 break;
228 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500229 } else if (*argptr == 'n') {
Ethan Yonker3aa66be2015-12-22 12:30:18 -0600230 DataManager::SetValue(TW_BACKUP_NAME, gui_parse_text("{@auto_generate}"));
231 if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
232 break;
Ethan Yonkera1674162014-11-06 08:35:10 -0600233 } else if (*argptr == 'p') {
234 Shutdown = true;
Dees_Troya449a6f2013-04-07 17:50:11 -0500235 } else if (*argptr == 's') {
236 ptr = argptr;
237 index2 = 0;
238 while (*ptr != '=' && *ptr != '\n')
239 ptr++;
240 if (*ptr) {
241 Reboot_Value = *ptr;
242 }
243 }
244 }
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200245 printf("\n");
Dees_Troya449a6f2013-04-07 17:50:11 -0500246 }
247
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200248 if(crash_counter == 0) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500249 property_list(Print_Prop, NULL);
250 printf("\n");
Vojtech Bocek0fc15732014-07-04 01:09:50 +0200251 } else {
252 printf("twrp.crash_counter=%d\n", crash_counter);
Dees_Troya449a6f2013-04-07 17:50:11 -0500253 }
254
255 // Check for and run startup script if script exists
256 TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot");
257 TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot");
258
259#ifdef TW_INCLUDE_INJECTTWRP
260 // Back up TWRP Ramdisk if needed:
261 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
Dees_Troya449a6f2013-04-07 17:50:11 -0500262 LOGINFO("Backing up TWRP ramdisk...\n");
263 if (Boot == NULL || Boot->Current_File_System != "emmc")
Vojtech Bocek05534202013-09-11 08:11:56 +0200264 TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
Dees_Troya449a6f2013-04-07 17:50:11 -0500265 else {
266 string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
Vojtech Bocek05534202013-09-11 08:11:56 +0200267 TWFunc::Exec_Cmd(injectcmd);
Dees_Troya449a6f2013-04-07 17:50:11 -0500268 }
269 LOGINFO("Backup of TWRP ramdisk done.\n");
270#endif
271
Dees_Troya449a6f2013-04-07 17:50:11 -0500272 TWFunc::Update_Log_File();
273 // Offer to decrypt if the device is encrypted
274 if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) {
275 LOGINFO("Is encrypted, do decrypt page first\n");
Ethan Yonkerfd0439e2015-01-14 11:08:13 -0600276 if (gui_startPage("decrypt", 1, 1) != 0) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500277 LOGERR("Failed to start decrypt GUI page.\n");
Ethan Yonkercf50da52015-01-12 21:59:07 -0600278 } else {
279 // Check for and load custom theme if present
280 gui_loadCustomResources();
Dees_Troya449a6f2013-04-07 17:50:11 -0500281 }
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600282 } else if (datamedia) {
283 if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
Ethan Yonkerd9ff3c52015-01-21 21:51:20 -0600284 LOGINFO("Failed to get default contexts and file mode for storage files.\n");
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600285 } else {
286 LOGINFO("Got default contexts and file mode for storage files.\n");
287 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500288 }
289
290 // Read the settings file
Ethan Yonker73da42c2014-09-03 11:30:33 -0500291#ifdef TW_HAS_MTP
292 // We unmount partitions sometimes during early boot which may override
293 // the default of MTP being enabled by auto toggling MTP off. This
294 // will force it back to enabled then get overridden by the settings
295 // file, assuming that an entry for tw_mtp_enabled is set.
296 DataManager::SetValue("tw_mtp_enabled", 1);
297#endif
Dees_Troya449a6f2013-04-07 17:50:11 -0500298 DataManager::ReadSettingsFile();
Ethan Yonker74db1572015-10-28 12:44:49 -0500299 PageManager::LoadLanguage(DataManager::GetStrValue("tw_language"));
300 GUIConsole::Translate_Now();
Vojtech Bocek2005a842014-03-11 19:40:34 +0100301
302 // Fixup the RTC clock on devices which require it
Vojtech Bocek67351dc2014-07-03 15:22:41 +0200303 if(crash_counter == 0)
304 TWFunc::Fixup_Time_On_Boot();
Vojtech Bocek2005a842014-03-11 19:40:34 +0100305
Dees_Troya449a6f2013-04-07 17:50:11 -0500306 // Run any outstanding OpenRecoveryScript
307 if (DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) {
308 OpenRecoveryScript::Run_OpenRecoveryScript();
309 }
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100310
Ethan Yonker6f49e112014-09-03 21:42:49 -0500311#ifdef TW_HAS_MTP
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400312 // Enable MTP?
Ethan Yonker6f49e112014-09-03 21:42:49 -0500313 char mtp_crash_check[PROPERTY_VALUE_MAX];
314 property_get("mtp.crash_check", mtp_crash_check, "0");
315 if (strcmp(mtp_crash_check, "0") == 0) {
316 property_set("mtp.crash_check", "1");
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600317 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 -0400318 LOGINFO("Enabling MTP during startup\n");
319 if (!PartitionManager.Enable_MTP())
320 PartitionManager.Disable_MTP();
321 else
Ethan Yonker74db1572015-10-28 12:44:49 -0500322 gui_msg("mtp_enabled=MTP Enabled");
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600323 } else {
324 PartitionManager.Disable_MTP();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400325 }
Ethan Yonker6f49e112014-09-03 21:42:49 -0500326 property_set("mtp.crash_check", "0");
327 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500328 gui_warn("mtp_crash=MTP Crashed, not starting MTP on boot.");
Ethan Yonker12055fa2014-09-04 08:06:53 -0500329 DataManager::SetValue("tw_mtp_enabled", 0);
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600330 PartitionManager.Disable_MTP();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400331 }
Ethan Yonkerdf7abac2014-12-29 10:48:17 -0600332#else
333 PartitionManager.Disable_MTP();
Ethan Yonker6f49e112014-09-03 21:42:49 -0500334#endif
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400335
Ethan Yonker89583ef2015-08-26 09:01:59 -0500336#ifndef TW_OEM_BUILD
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500337 // Check if system has never been changed
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500338 TWPartition* sys = PartitionManager.Find_Partition_By_Path("/system");
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500339 TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor");
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500340 if (sys) {
Ethan Yonker961d20e2015-06-29 14:00:03 -0500341 if ((DataManager::GetIntValue("tw_mount_system_ro") == 0 && sys->Check_Lifetime_Writes() == 0) || DataManager::GetIntValue("tw_mount_system_ro") == 2) {
342 if (DataManager::GetIntValue("tw_never_show_system_ro_page") == 0) {
343 DataManager::SetValue("tw_back", "main");
344 if (gui_startPage("system_readonly", 1, 1) != 0) {
345 LOGERR("Failed to start system_readonly GUI page.\n");
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500346 }
Ethan Yonker961d20e2015-06-29 14:00:03 -0500347 } else if (DataManager::GetIntValue("tw_mount_system_ro") == 0) {
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500348 sys->Change_Mount_Read_Only(false);
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500349 if (ven)
350 ven->Change_Mount_Read_Only(false);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500351 }
Ethan Yonker961d20e2015-06-29 14:00:03 -0500352 } else if (DataManager::GetIntValue("tw_mount_system_ro") == 1) {
353 // Do nothing, user selected to leave system read only
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500354 } else {
Ethan Yonker0e2c6572015-06-04 11:30:02 -0500355 sys->Change_Mount_Read_Only(false);
Ethan Yonker1673e3d2015-10-26 21:51:58 -0500356 if (ven)
357 ven->Change_Mount_Read_Only(false);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500358 }
359 }
Ethan Yonker89583ef2015-08-26 09:01:59 -0500360#endif
Dees_Troya449a6f2013-04-07 17:50:11 -0500361 // Launch the main GUI
362 gui_start();
363
Ethan Yonker89583ef2015-08-26 09:01:59 -0500364#ifndef TW_OEM_BUILD
Ethan Yonker9132d912015-02-02 10:32:49 -0600365 // Disable flashing of stock recovery
366 TWFunc::Disable_Stock_Recovery_Replace();
Dees_Troya449a6f2013-04-07 17:50:11 -0500367 // Check for su to see if the device is rooted or not
Matt Mower95460192015-11-18 10:31:33 -0600368 if (DataManager::GetIntValue("tw_mount_system_ro") == 0 && PartitionManager.Mount_By_Path("/system", false)) {
Ethan Yonker051f4762016-01-17 17:54:31 -0600369 // read /system/build.prop to get sdk version and do not offer to root if running M or higher (sdk version 23 == M)
370 string sdkverstr = TWFunc::System_Property_Get("ro.build.version.sdk");
371 int sdkver = 23;
372 if (!sdkverstr.empty()) {
373 sdkver = atoi(sdkverstr.c_str());
374 }
375 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") && sdkver < 23) {
Dees_Troya449a6f2013-04-07 17:50:11 -0500376 // Device doesn't have su installed
377 DataManager::SetValue("tw_busy", 1);
Ethan Yonkerfd0439e2015-01-14 11:08:13 -0600378 if (gui_startPage("installsu", 1, 1) != 0) {
Dees Troyf193f882013-09-11 14:56:20 +0000379 LOGERR("Failed to start SuperSU install page.\n");
Dees_Troya449a6f2013-04-07 17:50:11 -0500380 }
Dees_Troya449a6f2013-04-07 17:50:11 -0500381 }
382 sync();
383 PartitionManager.UnMount_By_Path("/system", false);
384 }
Ethan Yonker89583ef2015-08-26 09:01:59 -0500385#endif
Dees_Troya449a6f2013-04-07 17:50:11 -0500386
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200387 // Reboot
Dees_Troya449a6f2013-04-07 17:50:11 -0500388 TWFunc::Update_Intent_File(Reboot_Value);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200389 TWFunc::Update_Log_File();
Ethan Yonker74db1572015-10-28 12:44:49 -0500390 gui_msg(Msg("rebooting=Rebooting..."));
Dees_Troya449a6f2013-04-07 17:50:11 -0500391 string Reboot_Arg;
392 DataManager::GetValue("tw_reboot_arg", Reboot_Arg);
393 if (Reboot_Arg == "recovery")
394 TWFunc::tw_reboot(rb_recovery);
395 else if (Reboot_Arg == "poweroff")
396 TWFunc::tw_reboot(rb_poweroff);
397 else if (Reboot_Arg == "bootloader")
398 TWFunc::tw_reboot(rb_bootloader);
399 else if (Reboot_Arg == "download")
400 TWFunc::tw_reboot(rb_download);
401 else
402 TWFunc::tw_reboot(rb_system);
403
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200404 return 0;
Dees_Troya449a6f2013-04-07 17:50:11 -0500405}