Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 1 | /* |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 2 | 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_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 6 | |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 7 | 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_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 11 | |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 12 | 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_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <time.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | #include "cutils/properties.h" |
| 25 | extern "C" { |
| 26 | #include "minadbd/adb.h" |
| 27 | #include "bootloader.h" |
| 28 | } |
| 29 | |
| 30 | #ifdef ANDROID_RB_RESTART |
| 31 | #include "cutils/android_reboot.h" |
| 32 | #else |
| 33 | #include <sys/reboot.h> |
| 34 | #endif |
| 35 | |
| 36 | extern "C" { |
| 37 | #include "gui/gui.h" |
| 38 | } |
| 39 | #include "twcommon.h" |
| 40 | #include "twrp-functions.hpp" |
| 41 | #include "data.hpp" |
| 42 | #include "partitions.hpp" |
| 43 | #include "openrecoveryscript.hpp" |
| 44 | #include "variables.h" |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 45 | #include "twrpDU.hpp" |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 46 | |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 47 | #ifdef HAVE_SELINUX |
| 48 | #include "selinux/label.h" |
| 49 | struct selabel_handle *selinux_handle; |
| 50 | #endif |
| 51 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 52 | TWPartitionManager PartitionManager; |
| 53 | int Log_Offset; |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 54 | bool datamedia; |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 55 | twrpDU du; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 56 | |
| 57 | static void Print_Prop(const char *key, const char *name, void *cookie) { |
| 58 | printf("%s=%s\n", key, name); |
| 59 | } |
| 60 | |
| 61 | int main(int argc, char **argv) { |
| 62 | // Recovery needs to install world-readable files, so clear umask |
| 63 | // set by init |
| 64 | umask(0); |
| 65 | |
| 66 | Log_Offset = 0; |
| 67 | |
| 68 | // Set up temporary log file (/tmp/recovery.log) |
| 69 | freopen(TMP_LOG_FILE, "a", stdout); |
| 70 | setbuf(stdout, NULL); |
| 71 | freopen(TMP_LOG_FILE, "a", stderr); |
| 72 | setbuf(stderr, NULL); |
| 73 | |
| 74 | // Handle ADB sideload |
| 75 | if (argc == 3 && strcmp(argv[1], "--adbd") == 0) { |
| 76 | adb_main(argv[2]); |
| 77 | return 0; |
| 78 | } |
| 79 | |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 80 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 81 | datamedia = true; |
| 82 | #endif |
| 83 | |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 84 | char crash_prop_val[PROPERTY_VALUE_MAX]; |
| 85 | int crash_counter; |
| 86 | property_get("twrp.crash_counter", crash_prop_val, "-1"); |
| 87 | crash_counter = atoi(crash_prop_val) + 1; |
| 88 | snprintf(crash_prop_val, sizeof(crash_prop_val), "%d", crash_counter); |
| 89 | property_set("twrp.crash_counter", crash_prop_val); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 90 | property_set("ro.twrp.boot", "1"); |
| 91 | property_set("ro.twrp.version", TW_VERSION_STR); |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 92 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 93 | time_t StartupTime = time(NULL); |
| 94 | printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&StartupTime)); |
| 95 | |
| 96 | // Load default values to set DataManager constants and handle ifdefs |
| 97 | DataManager::SetDefaultValues(); |
| 98 | printf("Starting the UI..."); |
| 99 | gui_init(); |
| 100 | printf("=> Linking mtab\n"); |
| 101 | symlink("/proc/mounts", "/etc/mtab"); |
Dees_Troy | 329383e | 2013-08-29 14:16:06 +0000 | [diff] [blame] | 102 | if (TWFunc::Path_Exists("/etc/twrp.fstab")) { |
| 103 | if (TWFunc::Path_Exists("/etc/recovery.fstab")) { |
| 104 | printf("Renaming regular /etc/recovery.fstab -> /etc/recovery.fstab.bak\n"); |
| 105 | rename("/etc/recovery.fstab", "/etc/recovery.fstab.bak"); |
| 106 | } |
| 107 | printf("Moving /etc/twrp.fstab -> /etc/recovery.fstab\n"); |
| 108 | rename("/etc/twrp.fstab", "/etc/recovery.fstab"); |
| 109 | } |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 110 | printf("=> Processing recovery.fstab\n"); |
| 111 | if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) { |
| 112 | LOGERR("Failing out of recovery due to problem with recovery.fstab.\n"); |
| 113 | return -1; |
| 114 | } |
| 115 | PartitionManager.Output_Partition_Logging(); |
| 116 | // Load up all the resources |
| 117 | gui_loadResources(); |
| 118 | |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 119 | #ifdef HAVE_SELINUX |
bigbiff bigbiff | c49d706 | 2013-10-11 20:28:00 -0400 | [diff] [blame] | 120 | if (TWFunc::Path_Exists("/prebuilt_file_contexts")) { |
| 121 | if (TWFunc::Path_Exists("/file_contexts")) { |
| 122 | printf("Renaming regular /file_contexts -> /file_contexts.bak\n"); |
| 123 | rename("/file_contexts", "/file_contexts.bak"); |
| 124 | } |
| 125 | printf("Moving /prebuilt_file_contexts -> /file_contexts\n"); |
| 126 | rename("/prebuilt_file_contexts", "/file_contexts"); |
| 127 | } |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 128 | struct selinux_opt selinux_options[] = { |
| 129 | { SELABEL_OPT_PATH, "/file_contexts" } |
| 130 | }; |
bigbiff bigbiff | c49d706 | 2013-10-11 20:28:00 -0400 | [diff] [blame] | 131 | selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1); |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 132 | if (!selinux_handle) |
| 133 | printf("No file contexts for SELinux\n"); |
| 134 | else |
| 135 | printf("SELinux contexts loaded from /file_contexts\n"); |
Dees Troy | 995e88c | 2013-11-26 21:39:14 +0000 | [diff] [blame] | 136 | { // Check to ensure SELinux can be supported by the kernel |
| 137 | char *contexts = NULL; |
Dees Troy | 8d0eb13 | 2013-12-06 16:55:41 +0000 | [diff] [blame] | 138 | |
| 139 | if (PartitionManager.Mount_By_Path("/cache", true) && TWFunc::Path_Exists("/cache/recovery")) { |
| 140 | lgetfilecon("/cache/recovery", &contexts); |
| 141 | if (!contexts) { |
| 142 | lsetfilecon("/cache/recovery", "test"); |
| 143 | lgetfilecon("/cache/recovery", &contexts); |
| 144 | } |
| 145 | } else { |
| 146 | LOGINFO("Could not check /cache/recovery SELinux contexts, using /sbin/teamwin instead which may be inaccurate.\n"); |
| 147 | lgetfilecon("/sbin/teamwin", &contexts); |
| 148 | } |
Dees Troy | 995e88c | 2013-11-26 21:39:14 +0000 | [diff] [blame] | 149 | if (!contexts) { |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 150 | gui_print_color("warning", "Kernel does not have support for reading SELinux contexts.\n"); |
Dees Troy | 995e88c | 2013-11-26 21:39:14 +0000 | [diff] [blame] | 151 | } else { |
| 152 | free(contexts); |
| 153 | gui_print("Full SELinux support is present.\n"); |
| 154 | } |
| 155 | } |
| 156 | #else |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 157 | gui_print_color("warning", "No SELinux support (no libselinux).\n"); |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 158 | #endif |
| 159 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 160 | PartitionManager.Mount_By_Path("/cache", true); |
| 161 | |
| 162 | string Zip_File, Reboot_Value; |
| 163 | bool Cache_Wipe = false, Factory_Reset = false, Perform_Backup = false; |
| 164 | |
| 165 | { |
Dees_Troy | 1669f89 | 2013-09-04 18:35:08 +0000 | [diff] [blame] | 166 | TWPartition* misc = PartitionManager.Find_Partition_By_Path("/misc"); |
| 167 | if (misc != NULL) { |
| 168 | if (misc->Current_File_System == "emmc") { |
| 169 | set_device_type('e'); |
| 170 | set_device_name(misc->Actual_Block_Device.c_str()); |
| 171 | } else if (misc->Current_File_System == "mtd") { |
| 172 | set_device_type('m'); |
| 173 | set_device_name(misc->MTD_Name.c_str()); |
| 174 | } else { |
| 175 | LOGERR("Unknown file system for /misc\n"); |
| 176 | } |
| 177 | } |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 178 | get_args(&argc, &argv); |
| 179 | |
| 180 | int index, index2, len; |
| 181 | char* argptr; |
| 182 | char* ptr; |
| 183 | printf("Startup Commands: "); |
| 184 | for (index = 1; index < argc; index++) { |
| 185 | argptr = argv[index]; |
| 186 | printf(" '%s'", argv[index]); |
| 187 | len = strlen(argv[index]); |
| 188 | if (*argptr == '-') {argptr++; len--;} |
| 189 | if (*argptr == '-') {argptr++; len--;} |
| 190 | if (*argptr == 'u') { |
| 191 | ptr = argptr; |
| 192 | index2 = 0; |
| 193 | while (*ptr != '=' && *ptr != '\n') |
| 194 | ptr++; |
Kevin Steck | 7b69e9d | 2013-10-17 18:24:31 -0400 | [diff] [blame] | 195 | // skip the = before grabbing Zip_File |
| 196 | while (*ptr == '=') |
| 197 | ptr++; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 198 | if (*ptr) { |
| 199 | Zip_File = ptr; |
| 200 | } else |
| 201 | LOGERR("argument error specifying zip file\n"); |
| 202 | } else if (*argptr == 'w') { |
| 203 | if (len == 9) |
| 204 | Factory_Reset = true; |
| 205 | else if (len == 10) |
| 206 | Cache_Wipe = true; |
| 207 | } else if (*argptr == 'n') { |
| 208 | Perform_Backup = true; |
| 209 | } else if (*argptr == 's') { |
| 210 | ptr = argptr; |
| 211 | index2 = 0; |
| 212 | while (*ptr != '=' && *ptr != '\n') |
| 213 | ptr++; |
| 214 | if (*ptr) { |
| 215 | Reboot_Value = *ptr; |
| 216 | } |
| 217 | } |
| 218 | } |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 219 | printf("\n"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 222 | if(crash_counter == 0) { |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 223 | property_list(Print_Prop, NULL); |
| 224 | printf("\n"); |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 225 | } else { |
| 226 | printf("twrp.crash_counter=%d\n", crash_counter); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Check for and run startup script if script exists |
| 230 | TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot"); |
| 231 | TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot"); |
| 232 | |
| 233 | #ifdef TW_INCLUDE_INJECTTWRP |
| 234 | // Back up TWRP Ramdisk if needed: |
| 235 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 236 | LOGINFO("Backing up TWRP ramdisk...\n"); |
| 237 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 238 | TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 239 | else { |
| 240 | string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device; |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 241 | TWFunc::Exec_Cmd(injectcmd); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 242 | } |
| 243 | LOGINFO("Backup of TWRP ramdisk done.\n"); |
| 244 | #endif |
| 245 | |
| 246 | bool Keep_Going = true; |
| 247 | if (Perform_Backup) { |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 248 | DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 249 | if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n")) |
| 250 | Keep_Going = false; |
| 251 | } |
| 252 | if (Keep_Going && !Zip_File.empty()) { |
| 253 | string ORSCommand = "install " + Zip_File; |
| 254 | |
| 255 | if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand)) |
| 256 | Keep_Going = false; |
| 257 | } |
| 258 | if (Keep_Going) { |
| 259 | if (Factory_Reset) { |
| 260 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n")) |
| 261 | Keep_Going = false; |
| 262 | } else if (Cache_Wipe) { |
| 263 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n")) |
| 264 | Keep_Going = false; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | TWFunc::Update_Log_File(); |
| 269 | // Offer to decrypt if the device is encrypted |
| 270 | if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) { |
| 271 | LOGINFO("Is encrypted, do decrypt page first\n"); |
| 272 | if (gui_startPage("decrypt") != 0) { |
| 273 | LOGERR("Failed to start decrypt GUI page.\n"); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // Read the settings file |
Ethan Yonker | 73da42c | 2014-09-03 11:30:33 -0500 | [diff] [blame] | 278 | #ifdef TW_HAS_MTP |
| 279 | // We unmount partitions sometimes during early boot which may override |
| 280 | // the default of MTP being enabled by auto toggling MTP off. This |
| 281 | // will force it back to enabled then get overridden by the settings |
| 282 | // file, assuming that an entry for tw_mtp_enabled is set. |
| 283 | DataManager::SetValue("tw_mtp_enabled", 1); |
| 284 | #endif |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 285 | DataManager::ReadSettingsFile(); |
Vojtech Bocek | 2005a84 | 2014-03-11 19:40:34 +0100 | [diff] [blame] | 286 | |
| 287 | // Fixup the RTC clock on devices which require it |
Vojtech Bocek | 67351dc | 2014-07-03 15:22:41 +0200 | [diff] [blame] | 288 | if(crash_counter == 0) |
| 289 | TWFunc::Fixup_Time_On_Boot(); |
Vojtech Bocek | 2005a84 | 2014-03-11 19:40:34 +0100 | [diff] [blame] | 290 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 291 | // Run any outstanding OpenRecoveryScript |
| 292 | if (DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) { |
| 293 | OpenRecoveryScript::Run_OpenRecoveryScript(); |
| 294 | } |
Vojtech Bocek | d0e38bc | 2014-02-03 23:36:57 +0100 | [diff] [blame] | 295 | |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 296 | #ifdef TW_HAS_MTP |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 297 | // Enable MTP? |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 298 | char mtp_crash_check[PROPERTY_VALUE_MAX]; |
| 299 | property_get("mtp.crash_check", mtp_crash_check, "0"); |
| 300 | if (strcmp(mtp_crash_check, "0") == 0) { |
| 301 | property_set("mtp.crash_check", "1"); |
| 302 | if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) { |
| 303 | if (DataManager::GetIntValue(TW_IS_DECRYPTED) != 0 && DataManager::GetIntValue("tw_mtp_enabled") == 1) { |
| 304 | LOGINFO("Enabling MTP during startup\n"); |
| 305 | if (!PartitionManager.Enable_MTP()) |
| 306 | PartitionManager.Disable_MTP(); |
| 307 | else |
| 308 | gui_print("MTP Enabled\n"); |
| 309 | } |
| 310 | } else if (DataManager::GetIntValue("tw_mtp_enabled") == 1) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 311 | LOGINFO("Enabling MTP during startup\n"); |
| 312 | if (!PartitionManager.Enable_MTP()) |
| 313 | PartitionManager.Disable_MTP(); |
| 314 | else |
| 315 | gui_print("MTP Enabled\n"); |
| 316 | } |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 317 | property_set("mtp.crash_check", "0"); |
| 318 | } else { |
| 319 | gui_print_color("warning", "MTP Crashed, not starting MTP on boot.\n"); |
Ethan Yonker | 12055fa | 2014-09-04 08:06:53 -0500 | [diff] [blame] | 320 | DataManager::SetValue("tw_mtp_enabled", 0); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 321 | } |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 322 | #endif |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 323 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 324 | // Launch the main GUI |
| 325 | gui_start(); |
| 326 | |
| 327 | // Check for su to see if the device is rooted or not |
| 328 | if (PartitionManager.Mount_By_Path("/system", false)) { |
| 329 | // Disable flashing of stock recovery |
dhacker29 | 30f100e | 2014-07-15 21:33:29 -0400 | [diff] [blame] | 330 | if (TWFunc::Path_Exists("/system/recovery-from-boot.p") && TWFunc::Path_Exists("/system/etc/install-recovery.sh")) { |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 331 | rename("/system/recovery-from-boot.p", "/system/recovery-from-boot.bak"); |
| 332 | gui_print("Renamed stock recovery file in /system to prevent\nthe stock ROM from replacing TWRP.\n"); |
| 333 | } |
| 334 | if (TWFunc::Path_Exists("/supersu/su") && !TWFunc::Path_Exists("/system/bin/su") && !TWFunc::Path_Exists("/system/xbin/su") && !TWFunc::Path_Exists("/system/bin/.ext/.su")) { |
| 335 | // Device doesn't have su installed |
| 336 | DataManager::SetValue("tw_busy", 1); |
| 337 | if (gui_startPage("installsu") != 0) { |
Dees Troy | f193f88 | 2013-09-11 14:56:20 +0000 | [diff] [blame] | 338 | LOGERR("Failed to start SuperSU install page.\n"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 339 | } |
| 340 | } else if (TWFunc::Check_su_Perms() > 0) { |
| 341 | // su perms are set incorrectly |
Dees Troy | f193f88 | 2013-09-11 14:56:20 +0000 | [diff] [blame] | 342 | LOGINFO("Root permissions appear to be lost... fixing. (This will always happen on 4.3+ ROMs with SELinux.\n"); |
| 343 | TWFunc::Fix_su_Perms(); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 344 | } |
| 345 | sync(); |
| 346 | PartitionManager.UnMount_By_Path("/system", false); |
| 347 | } |
| 348 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 349 | // Reboot |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 350 | TWFunc::Update_Intent_File(Reboot_Value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 351 | TWFunc::Update_Log_File(); |
| 352 | gui_print("Rebooting...\n"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 353 | string Reboot_Arg; |
| 354 | DataManager::GetValue("tw_reboot_arg", Reboot_Arg); |
| 355 | if (Reboot_Arg == "recovery") |
| 356 | TWFunc::tw_reboot(rb_recovery); |
| 357 | else if (Reboot_Arg == "poweroff") |
| 358 | TWFunc::tw_reboot(rb_poweroff); |
| 359 | else if (Reboot_Arg == "bootloader") |
| 360 | TWFunc::tw_reboot(rb_bootloader); |
| 361 | else if (Reboot_Arg == "download") |
| 362 | TWFunc::tw_reboot(rb_download); |
| 363 | else |
| 364 | TWFunc::tw_reboot(rb_system); |
| 365 | |
| 366 | #ifdef ANDROID_RB_RESTART |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 367 | android_reboot(ANDROID_RB_RESTART, 0, 0); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 368 | #else |
| 369 | reboot(RB_AUTOBOOT); |
| 370 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 371 | return 0; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 372 | } |