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> |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 18 | #include <string> |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 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> |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 24 | #include "gui/twmsg.h" |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 25 | |
| 26 | #include "cutils/properties.h" |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 27 | #include "bootloader_message_twrp/include/bootloader_message_twrp/bootloader_message.h" |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 28 | |
| 29 | #ifdef ANDROID_RB_RESTART |
| 30 | #include "cutils/android_reboot.h" |
| 31 | #else |
| 32 | #include <sys/reboot.h> |
| 33 | #endif |
| 34 | |
| 35 | extern "C" { |
| 36 | #include "gui/gui.h" |
| 37 | } |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 38 | #include "set_metadata.h" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 39 | #include "gui/gui.hpp" |
| 40 | #include "gui/pages.hpp" |
| 41 | #include "gui/objects.hpp" |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 42 | #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 bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 48 | #include "twrpAdbBuFifo.hpp" |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 49 | #ifdef TW_USE_NEW_MINADBD |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 50 | #include "minadbd/minadbd.h" |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 51 | #else |
| 52 | extern "C" { |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 53 | #include "minadbd21/adb.h" |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 54 | } |
| 55 | #endif |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 56 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 57 | //extern int adb_server_main(int is_daemon, int server_port, int /* reply_fd */); |
Ethan Yonker | 534d4e0 | 2016-08-26 10:05:03 -0500 | [diff] [blame] | 58 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 59 | TWPartitionManager PartitionManager; |
| 60 | int Log_Offset; |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 61 | bool datamedia; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 62 | |
| 63 | static void Print_Prop(const char *key, const char *name, void *cookie) { |
| 64 | printf("%s=%s\n", key, name); |
| 65 | } |
| 66 | |
| 67 | int main(int argc, char **argv) { |
| 68 | // Recovery needs to install world-readable files, so clear umask |
| 69 | // set by init |
| 70 | umask(0); |
| 71 | |
| 72 | Log_Offset = 0; |
| 73 | |
| 74 | // Set up temporary log file (/tmp/recovery.log) |
| 75 | freopen(TMP_LOG_FILE, "a", stdout); |
| 76 | setbuf(stdout, NULL); |
| 77 | freopen(TMP_LOG_FILE, "a", stderr); |
| 78 | setbuf(stderr, NULL); |
| 79 | |
Ethan Yonker | f9f99bc | 2014-12-29 09:10:34 -0600 | [diff] [blame] | 80 | signal(SIGPIPE, SIG_IGN); |
| 81 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 82 | // Handle ADB sideload |
| 83 | if (argc == 3 && strcmp(argv[1], "--adbd") == 0) { |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 84 | property_set("ctl.stop", "adbd"); |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 85 | #ifdef TW_USE_NEW_MINADBD |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 86 | //adb_server_main(0, DEFAULT_ADB_PORT, -1); TODO fix this for android8 |
| 87 | minadbd_main(); |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 88 | #else |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 89 | adb_main(argv[2]); |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 90 | #endif |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 94 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 95 | datamedia = true; |
| 96 | #endif |
| 97 | |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 98 | char crash_prop_val[PROPERTY_VALUE_MAX]; |
| 99 | int crash_counter; |
| 100 | property_get("twrp.crash_counter", crash_prop_val, "-1"); |
| 101 | crash_counter = atoi(crash_prop_val) + 1; |
| 102 | snprintf(crash_prop_val, sizeof(crash_prop_val), "%d", crash_counter); |
| 103 | property_set("twrp.crash_counter", crash_prop_val); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 104 | property_set("ro.twrp.boot", "1"); |
| 105 | property_set("ro.twrp.version", TW_VERSION_STR); |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 106 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 107 | time_t StartupTime = time(NULL); |
that | 0e2140e | 2016-08-10 21:04:26 +0200 | [diff] [blame] | 108 | printf("Starting TWRP %s-%s on %s (pid %d)\n", TW_VERSION_STR, TW_GIT_REVISION, ctime(&StartupTime), getpid()); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 109 | |
| 110 | // Load default values to set DataManager constants and handle ifdefs |
| 111 | DataManager::SetDefaultValues(); |
that | 0e2140e | 2016-08-10 21:04:26 +0200 | [diff] [blame] | 112 | printf("Starting the UI...\n"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 113 | gui_init(); |
| 114 | printf("=> Linking mtab\n"); |
| 115 | symlink("/proc/mounts", "/etc/mtab"); |
Ethan Yonker | 53273ec | 2018-03-09 11:22:54 -0600 | [diff] [blame] | 116 | std::string fstab_filename = "/etc/twrp.fstab"; |
| 117 | if (!TWFunc::Path_Exists(fstab_filename)) { |
| 118 | fstab_filename = "/etc/recovery.fstab"; |
Dees_Troy | 329383e | 2013-08-29 14:16:06 +0000 | [diff] [blame] | 119 | } |
Ethan Yonker | 53273ec | 2018-03-09 11:22:54 -0600 | [diff] [blame] | 120 | printf("=> Processing %s\n", fstab_filename.c_str()); |
| 121 | if (!PartitionManager.Process_Fstab(fstab_filename, 1)) { |
| 122 | LOGERR("Failing out of recovery due to problem with fstab.\n"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 123 | return -1; |
| 124 | } |
| 125 | PartitionManager.Output_Partition_Logging(); |
| 126 | // Load up all the resources |
| 127 | gui_loadResources(); |
| 128 | |
Matt Mower | 23d8aae | 2017-01-06 14:30:33 -0600 | [diff] [blame] | 129 | bool Shutdown = false; |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 130 | string Send_Intent = ""; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 131 | { |
Dees_Troy | 1669f89 | 2013-09-04 18:35:08 +0000 | [diff] [blame] | 132 | TWPartition* misc = PartitionManager.Find_Partition_By_Path("/misc"); |
| 133 | if (misc != NULL) { |
| 134 | if (misc->Current_File_System == "emmc") { |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 135 | set_misc_device(misc->Actual_Block_Device.c_str()); |
Dees_Troy | 1669f89 | 2013-09-04 18:35:08 +0000 | [diff] [blame] | 136 | } else { |
Matt Mower | 3626bdc | 2017-01-06 13:45:54 -0600 | [diff] [blame] | 137 | LOGERR("Only emmc /misc is supported\n"); |
Dees_Troy | 1669f89 | 2013-09-04 18:35:08 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 140 | get_args(&argc, &argv); |
| 141 | |
| 142 | int index, index2, len; |
| 143 | char* argptr; |
| 144 | char* ptr; |
| 145 | printf("Startup Commands: "); |
| 146 | for (index = 1; index < argc; index++) { |
| 147 | argptr = argv[index]; |
| 148 | printf(" '%s'", argv[index]); |
| 149 | len = strlen(argv[index]); |
| 150 | if (*argptr == '-') {argptr++; len--;} |
| 151 | if (*argptr == '-') {argptr++; len--;} |
| 152 | if (*argptr == 'u') { |
| 153 | ptr = argptr; |
| 154 | index2 = 0; |
| 155 | while (*ptr != '=' && *ptr != '\n') |
| 156 | ptr++; |
Kevin Steck | 7b69e9d | 2013-10-17 18:24:31 -0400 | [diff] [blame] | 157 | // skip the = before grabbing Zip_File |
| 158 | while (*ptr == '=') |
| 159 | ptr++; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 160 | if (*ptr) { |
Ethan Yonker | 3aa66be | 2015-12-22 12:30:18 -0600 | [diff] [blame] | 161 | string ORSCommand = "install "; |
| 162 | ORSCommand.append(ptr); |
| 163 | |
| 164 | if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand)) |
| 165 | break; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 166 | } else |
| 167 | LOGERR("argument error specifying zip file\n"); |
| 168 | } else if (*argptr == 'w') { |
Ethan Yonker | 3aa66be | 2015-12-22 12:30:18 -0600 | [diff] [blame] | 169 | if (len == 9) { |
| 170 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n")) |
| 171 | break; |
| 172 | } else if (len == 10) { |
| 173 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n")) |
| 174 | break; |
| 175 | } |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 176 | // Other 'w' items are wipe_ab and wipe_package_size which are related to bricking the device remotely. We will not bother to suppor these as having TWRP probably makes "bricking" the device in this manner useless |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 177 | } else if (*argptr == 'n') { |
Ethan Yonker | 3aa66be | 2015-12-22 12:30:18 -0600 | [diff] [blame] | 178 | DataManager::SetValue(TW_BACKUP_NAME, gui_parse_text("{@auto_generate}")); |
| 179 | if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n")) |
| 180 | break; |
Ethan Yonker | a167416 | 2014-11-06 08:35:10 -0600 | [diff] [blame] | 181 | } else if (*argptr == 'p') { |
| 182 | Shutdown = true; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 183 | } else if (*argptr == 's') { |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 184 | if (strncmp(argptr, "send_intent", strlen("send_intent")) == 0) { |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 185 | ptr = argptr + strlen("send_intent") + 1; |
| 186 | Send_Intent = *ptr; |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 187 | } else if (strncmp(argptr, "security", strlen("security")) == 0) { |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 188 | LOGINFO("Security update\n"); |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 189 | } else if (strncmp(argptr, "sideload", strlen("sideload")) == 0) { |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 190 | if (!OpenRecoveryScript::Insert_ORS_Command("sideload\n")) |
| 191 | break; |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 192 | } else if (strncmp(argptr, "stages", strlen("stages")) == 0) { |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 193 | LOGINFO("ignoring stages command\n"); |
| 194 | } |
| 195 | } else if (*argptr == 'r') { |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 196 | if (strncmp(argptr, "reason", strlen("reason")) == 0) { |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 197 | ptr = argptr + strlen("reason") + 1; |
| 198 | gui_print("%s\n", ptr); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 202 | printf("\n"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 205 | if (crash_counter == 0) { |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 206 | property_list(Print_Prop, NULL); |
| 207 | printf("\n"); |
Vojtech Bocek | 0fc1573 | 2014-07-04 01:09:50 +0200 | [diff] [blame] | 208 | } else { |
| 209 | printf("twrp.crash_counter=%d\n", crash_counter); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | // Check for and run startup script if script exists |
| 213 | TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot"); |
| 214 | TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot"); |
| 215 | |
| 216 | #ifdef TW_INCLUDE_INJECTTWRP |
| 217 | // Back up TWRP Ramdisk if needed: |
| 218 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 219 | LOGINFO("Backing up TWRP ramdisk...\n"); |
| 220 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 221 | TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img"); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 222 | else { |
| 223 | 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] | 224 | TWFunc::Exec_Cmd(injectcmd); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 225 | } |
| 226 | LOGINFO("Backup of TWRP ramdisk done.\n"); |
| 227 | #endif |
| 228 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 229 | // Offer to decrypt if the device is encrypted |
| 230 | if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) { |
Captain Throwback | f8d0e21 | 2019-07-04 14:26:39 -0400 | [diff] [blame] | 231 | LOGINFO("Is encrypted, do decrypt page first\n"); |
| 232 | if (gui_startPage("decrypt", 1, 1) != 0) { |
| 233 | LOGERR("Failed to start decrypt GUI page.\n"); |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 234 | } else { |
Captain Throwback | f8d0e21 | 2019-07-04 14:26:39 -0400 | [diff] [blame] | 235 | // Check for and load custom theme if present |
| 236 | TWFunc::check_selinux_support(); |
| 237 | gui_loadCustomResources(); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 238 | } |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 239 | } else if (datamedia) { |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 240 | TWFunc::check_selinux_support(); |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 241 | if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) { |
Ethan Yonker | d9ff3c5 | 2015-01-21 21:51:20 -0600 | [diff] [blame] | 242 | 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] | 243 | } else { |
| 244 | LOGINFO("Got default contexts and file mode for storage files.\n"); |
| 245 | } |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 246 | } |
| 247 | |
Vojtech Bocek | 2005a84 | 2014-03-11 19:40:34 +0100 | [diff] [blame] | 248 | // Fixup the RTC clock on devices which require it |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 249 | if (crash_counter == 0) |
Vojtech Bocek | 67351dc | 2014-07-03 15:22:41 +0200 | [diff] [blame] | 250 | TWFunc::Fixup_Time_On_Boot(); |
Vojtech Bocek | 2005a84 | 2014-03-11 19:40:34 +0100 | [diff] [blame] | 251 | |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 252 | // Read the settings file |
| 253 | TWFunc::Update_Log_File(); |
| 254 | DataManager::ReadSettingsFile(); |
| 255 | PageManager::LoadLanguage(DataManager::GetStrValue("tw_language")); |
| 256 | GUIConsole::Translate_Now(); |
| 257 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 258 | // Run any outstanding OpenRecoveryScript |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 259 | std::string cacheDir = TWFunc::get_cache_dir(); |
| 260 | std::string orsFile = cacheDir + "/recovery/openrecoveryscript"; |
Captain Throwback | f8d0e21 | 2019-07-04 14:26:39 -0400 | [diff] [blame] | 261 | |
| 262 | if (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || (DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 && TWFunc::Path_Exists(orsFile))) { |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 263 | OpenRecoveryScript::Run_OpenRecoveryScript(); |
| 264 | } |
Vojtech Bocek | d0e38bc | 2014-02-03 23:36:57 +0100 | [diff] [blame] | 265 | |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 266 | #ifdef TW_HAS_MTP |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 267 | char mtp_crash_check[PROPERTY_VALUE_MAX]; |
| 268 | property_get("mtp.crash_check", mtp_crash_check, "0"); |
Matt Mower | 653a170 | 2017-02-16 10:38:52 -0600 | [diff] [blame] | 269 | if (DataManager::GetIntValue("tw_mtp_enabled") |
| 270 | && !strcmp(mtp_crash_check, "0") && !crash_counter |
| 271 | && (!DataManager::GetIntValue(TW_IS_ENCRYPTED) || DataManager::GetIntValue(TW_IS_DECRYPTED))) { |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 272 | property_set("mtp.crash_check", "1"); |
Matt Mower | 653a170 | 2017-02-16 10:38:52 -0600 | [diff] [blame] | 273 | LOGINFO("Starting MTP\n"); |
| 274 | if (!PartitionManager.Enable_MTP()) |
Ethan Yonker | df7abac | 2014-12-29 10:48:17 -0600 | [diff] [blame] | 275 | PartitionManager.Disable_MTP(); |
Matt Mower | 653a170 | 2017-02-16 10:38:52 -0600 | [diff] [blame] | 276 | else |
| 277 | gui_msg("mtp_enabled=MTP Enabled"); |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 278 | property_set("mtp.crash_check", "0"); |
Matt Mower | 653a170 | 2017-02-16 10:38:52 -0600 | [diff] [blame] | 279 | } else if (strcmp(mtp_crash_check, "0")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 280 | gui_warn("mtp_crash=MTP Crashed, not starting MTP on boot."); |
Ethan Yonker | 12055fa | 2014-09-04 08:06:53 -0500 | [diff] [blame] | 281 | DataManager::SetValue("tw_mtp_enabled", 0); |
Ethan Yonker | df7abac | 2014-12-29 10:48:17 -0600 | [diff] [blame] | 282 | PartitionManager.Disable_MTP(); |
Matt Mower | 653a170 | 2017-02-16 10:38:52 -0600 | [diff] [blame] | 283 | } else if (crash_counter == 1) { |
| 284 | LOGINFO("TWRP crashed; disabling MTP as a precaution.\n"); |
| 285 | PartitionManager.Disable_MTP(); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 286 | } |
Ethan Yonker | 6f49e11 | 2014-09-03 21:42:49 -0500 | [diff] [blame] | 287 | #endif |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 288 | |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 289 | #ifndef TW_OEM_BUILD |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 290 | // Check if system has never been changed |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 291 | TWPartition* sys = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path()); |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 292 | TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor"); |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 293 | |
Ethan Yonker | 0e2c657 | 2015-06-04 11:30:02 -0500 | [diff] [blame] | 294 | if (sys) { |
Ethan Yonker | 961d20e | 2015-06-29 14:00:03 -0500 | [diff] [blame] | 295 | if ((DataManager::GetIntValue("tw_mount_system_ro") == 0 && sys->Check_Lifetime_Writes() == 0) || DataManager::GetIntValue("tw_mount_system_ro") == 2) { |
| 296 | if (DataManager::GetIntValue("tw_never_show_system_ro_page") == 0) { |
| 297 | DataManager::SetValue("tw_back", "main"); |
| 298 | if (gui_startPage("system_readonly", 1, 1) != 0) { |
| 299 | LOGERR("Failed to start system_readonly GUI page.\n"); |
Ethan Yonker | 0e2c657 | 2015-06-04 11:30:02 -0500 | [diff] [blame] | 300 | } |
Ethan Yonker | 961d20e | 2015-06-29 14:00:03 -0500 | [diff] [blame] | 301 | } else if (DataManager::GetIntValue("tw_mount_system_ro") == 0) { |
Ethan Yonker | 0e2c657 | 2015-06-04 11:30:02 -0500 | [diff] [blame] | 302 | sys->Change_Mount_Read_Only(false); |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 303 | if (ven) |
| 304 | ven->Change_Mount_Read_Only(false); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 305 | } |
Ethan Yonker | 961d20e | 2015-06-29 14:00:03 -0500 | [diff] [blame] | 306 | } else if (DataManager::GetIntValue("tw_mount_system_ro") == 1) { |
| 307 | // Do nothing, user selected to leave system read only |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 308 | } else { |
Ethan Yonker | 0e2c657 | 2015-06-04 11:30:02 -0500 | [diff] [blame] | 309 | sys->Change_Mount_Read_Only(false); |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 310 | if (ven) |
| 311 | ven->Change_Mount_Read_Only(false); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 312 | } |
| 313 | } |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 314 | #endif |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 315 | twrpAdbBuFifo *adb_bu_fifo = new twrpAdbBuFifo(); |
| 316 | adb_bu_fifo->threadAdbBuFifo(); |
| 317 | |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 318 | // Launch the main GUI |
| 319 | gui_start(); |
| 320 | |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 321 | #ifndef TW_OEM_BUILD |
Ethan Yonker | 9132d91 | 2015-02-02 10:32:49 -0600 | [diff] [blame] | 322 | // Disable flashing of stock recovery |
| 323 | TWFunc::Disable_Stock_Recovery_Replace(); |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 324 | #endif |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 325 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 326 | // Reboot |
Ethan Yonker | b523650 | 2016-11-19 22:24:59 -0600 | [diff] [blame] | 327 | TWFunc::Update_Intent_File(Send_Intent); |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 328 | delete adb_bu_fifo; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 329 | TWFunc::Update_Log_File(); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 330 | gui_msg(Msg("rebooting=Rebooting...")); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 331 | string Reboot_Arg; |
| 332 | DataManager::GetValue("tw_reboot_arg", Reboot_Arg); |
| 333 | if (Reboot_Arg == "recovery") |
| 334 | TWFunc::tw_reboot(rb_recovery); |
| 335 | else if (Reboot_Arg == "poweroff") |
| 336 | TWFunc::tw_reboot(rb_poweroff); |
| 337 | else if (Reboot_Arg == "bootloader") |
| 338 | TWFunc::tw_reboot(rb_bootloader); |
| 339 | else if (Reboot_Arg == "download") |
| 340 | TWFunc::tw_reboot(rb_download); |
mauronofrio | e9a49ef | 2018-10-03 13:38:16 +0200 | [diff] [blame] | 341 | else if (Reboot_Arg == "edl") |
| 342 | TWFunc::tw_reboot(rb_edl); |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 343 | else |
| 344 | TWFunc::tw_reboot(rb_system); |
| 345 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 346 | return 0; |
Dees_Troy | a449a6f | 2013-04-07 17:50:11 -0500 | [diff] [blame] | 347 | } |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 348 | |