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