The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <ctype.h> |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 18 | #include <dirent.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <getopt.h> |
| 22 | #include <limits.h> |
| 23 | #include <linux/input.h> |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 24 | #include <stdarg.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 28 | #include <sys/stat.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | #include <time.h> |
| 31 | #include <unistd.h> |
| 32 | |
| 33 | #include "bootloader.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | #include "common.h" |
| 35 | #include "cutils/properties.h" |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 36 | #ifdef ANDROID_RB_RESTART |
Ken Sumrall | 6e4472a | 2011-03-07 23:37:27 -0800 | [diff] [blame] | 37 | #include "cutils/android_reboot.h" |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 38 | #else |
| 39 | #include <sys/reboot.h> |
| 40 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 41 | #include "install.h" |
| 42 | #include "minui/minui.h" |
| 43 | #include "minzip/DirUtil.h" |
| 44 | #include "roots.h" |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 45 | #include "ui.h" |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 46 | #include "screen_ui.h" |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 47 | #include "device.h" |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 48 | #include "adb_install.h" |
| 49 | extern "C" { |
| 50 | #include "minadbd/adb.h" |
| 51 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 52 | |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 53 | extern "C" { |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 54 | #include "data.h" |
| 55 | #include "gui/gui.h" |
| 56 | } |
| 57 | #include "partitions.hpp" |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 58 | #include "variables.h" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 59 | #include "openrecoveryscript.hpp" |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 60 | #include "twrp-functions.hpp" |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 61 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 62 | TWPartitionManager PartitionManager; |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 63 | |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 64 | struct selabel_handle *sehandle; |
| 65 | |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 66 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 67 | static const struct option OPTIONS[] = { |
| 68 | { "send_intent", required_argument, NULL, 's' }, |
| 69 | { "update_package", required_argument, NULL, 'u' }, |
| 70 | { "wipe_data", no_argument, NULL, 'w' }, |
| 71 | { "wipe_cache", no_argument, NULL, 'c' }, |
Doug Zongker | 4bc9806 | 2010-09-03 11:00:13 -0700 | [diff] [blame] | 72 | { "show_text", no_argument, NULL, 't' }, |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 73 | { "just_exit", no_argument, NULL, 'x' }, |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 74 | { "locale", required_argument, NULL, 'l' }, |
Doug Zongker | 988500b | 2009-10-06 14:41:38 -0700 | [diff] [blame] | 75 | { NULL, 0, NULL, 0 }, |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Doug Zongker | da1ebae | 2013-05-16 11:23:48 -0700 | [diff] [blame] | 78 | #define LAST_LOG_FILE "/cache/recovery/last_log" |
| 79 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 80 | static const char *COMMAND_FILE = "/cache/recovery/command"; |
| 81 | static const char *INTENT_FILE = "/cache/recovery/intent"; |
| 82 | static const char *LOG_FILE = "/cache/recovery/log"; |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 83 | static const char *LAST_INSTALL_FILE = "/cache/recovery/last_install"; |
Doug Zongker | 8b240cc | 2012-08-29 15:19:29 -0700 | [diff] [blame] | 84 | static const char *LOCALE_FILE = "/cache/recovery/last_locale"; |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 85 | static const char *CACHE_ROOT = "/cache"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 86 | static const char *SDCARD_ROOT = "/sdcard"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 87 | static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 88 | static const char *TEMPORARY_INSTALL_FILE = "/tmp/last_install"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 89 | static const char *SIDELOAD_TEMP_DIR = "/tmp/sideload"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 90 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 91 | RecoveryUI* ui = NULL; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 92 | char* locale = NULL; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 93 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 94 | /* |
| 95 | * The recovery tool communicates with the main system through /cache files. |
| 96 | * /cache/recovery/command - INPUT - command line for tool, one arg per line |
| 97 | * /cache/recovery/log - OUTPUT - combined log file from recovery run(s) |
| 98 | * /cache/recovery/intent - OUTPUT - intent that was passed in |
| 99 | * |
| 100 | * The arguments which may be supplied in the recovery.command file: |
| 101 | * --send_intent=anystring - write the text out to recovery.intent |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 102 | * --update_package=path - verify install an OTA package file |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 103 | * --wipe_data - erase user data (and cache), then reboot |
| 104 | * --wipe_cache - wipe cache (but not user data), then reboot |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 105 | * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 106 | * --just_exit - do nothing; exit and reboot |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 107 | * |
| 108 | * After completing, we remove /cache/recovery/command and reboot. |
| 109 | * Arguments may also be supplied in the bootloader control block (BCB). |
| 110 | * These important scenarios must be safely restartable at any point: |
| 111 | * |
| 112 | * FACTORY RESET |
| 113 | * 1. user selects "factory reset" |
| 114 | * 2. main system writes "--wipe_data" to /cache/recovery/command |
| 115 | * 3. main system reboots into recovery |
| 116 | * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data" |
| 117 | * -- after this, rebooting will restart the erase -- |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 118 | * 5. erase_volume() reformats /data |
| 119 | * 6. erase_volume() reformats /cache |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 120 | * 7. finish_recovery() erases BCB |
| 121 | * -- after this, rebooting will restart the main system -- |
| 122 | * 8. main() calls reboot() to boot main system |
| 123 | * |
| 124 | * OTA INSTALL |
| 125 | * 1. main system downloads OTA package to /cache/some-filename.zip |
Doug Zongker | 9b125b0 | 2010-09-22 12:01:37 -0700 | [diff] [blame] | 126 | * 2. main system writes "--update_package=/cache/some-filename.zip" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 127 | * 3. main system reboots into recovery |
| 128 | * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..." |
| 129 | * -- after this, rebooting will attempt to reinstall the update -- |
| 130 | * 5. install_package() attempts to install the update |
| 131 | * NOTE: the package install must itself be restartable from any point |
| 132 | * 6. finish_recovery() erases BCB |
| 133 | * -- after this, rebooting will (try to) restart the main system -- |
| 134 | * 7. ** if install failed ** |
| 135 | * 7a. prompt_and_wait() shows an error icon and waits for the user |
| 136 | * 7b; the user reboots (pulling the battery, etc) into the main system |
| 137 | * 8. main() calls maybe_install_firmware_update() |
| 138 | * ** if the update contained radio/hboot firmware **: |
| 139 | * 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache" |
| 140 | * -- after this, rebooting will reformat cache & restart main system -- |
| 141 | * 8b. m_i_f_u() writes firmware image into raw cache partition |
| 142 | * 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache" |
| 143 | * -- after this, rebooting will attempt to reinstall firmware -- |
| 144 | * 8d. bootloader tries to flash firmware |
| 145 | * 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache") |
| 146 | * -- after this, rebooting will reformat cache & restart main system -- |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 147 | * 8f. erase_volume() reformats /cache |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 148 | * 8g. finish_recovery() erases BCB |
| 149 | * -- after this, rebooting will (try to) restart the main system -- |
| 150 | * 9. main() calls reboot() to boot main system |
| 151 | */ |
| 152 | |
| 153 | static const int MAX_ARG_LENGTH = 4096; |
| 154 | static const int MAX_ARGS = 100; |
| 155 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 156 | // open a given path, mounting partitions as necessary |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 157 | FILE* |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 158 | fopen_path(const char *path, const char *mode) { |
| 159 | if (ensure_path_mounted(path) != 0) { |
| 160 | LOGE("Can't mount %s\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | // When writing, try to create the containing directory, if necessary. |
| 165 | // Use generous permissions, the system (init.rc) will reset them. |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 166 | if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1, sehandle); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 167 | |
| 168 | FILE *fp = fopen(path, mode); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 169 | return fp; |
| 170 | } |
| 171 | |
| 172 | // close a file, log an error if the error indicator is set |
| 173 | static void |
| 174 | check_and_fclose(FILE *fp, const char *name) { |
| 175 | fflush(fp); |
| 176 | if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno)); |
| 177 | fclose(fp); |
| 178 | } |
| 179 | |
| 180 | // command line args come from, in decreasing precedence: |
| 181 | // - the actual command line |
| 182 | // - the bootloader control block (one per line, after "recovery") |
| 183 | // - the contents of COMMAND_FILE (one per line) |
| 184 | static void |
| 185 | get_args(int *argc, char ***argv) { |
| 186 | struct bootloader_message boot; |
| 187 | memset(&boot, 0, sizeof(boot)); |
| 188 | get_bootloader_message(&boot); // this may fail, leaving a zeroed structure |
| 189 | |
| 190 | if (boot.command[0] != 0 && boot.command[0] != 255) { |
| 191 | LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command); |
| 192 | } |
| 193 | |
| 194 | if (boot.status[0] != 0 && boot.status[0] != 255) { |
| 195 | LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status); |
| 196 | } |
| 197 | |
| 198 | // --- if arguments weren't supplied, look in the bootloader control block |
| 199 | if (*argc <= 1) { |
| 200 | boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination |
| 201 | const char *arg = strtok(boot.recovery, "\n"); |
| 202 | if (arg != NULL && !strcmp(arg, "recovery")) { |
| 203 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 204 | (*argv)[0] = strdup(arg); |
| 205 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 206 | if ((arg = strtok(NULL, "\n")) == NULL) break; |
| 207 | (*argv)[*argc] = strdup(arg); |
| 208 | } |
| 209 | LOGI("Got arguments from boot message\n"); |
| 210 | } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) { |
| 211 | LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // --- if that doesn't work, try the command file |
| 216 | if (*argc <= 1) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 217 | FILE *fp = fopen_path(COMMAND_FILE, "r"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 218 | if (fp != NULL) { |
Jin Feng | 93ffa75 | 2013-06-04 17:46:24 +0800 | [diff] [blame] | 219 | char *token; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 220 | char *argv0 = (*argv)[0]; |
| 221 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 222 | (*argv)[0] = argv0; // use the same program name |
| 223 | |
| 224 | char buf[MAX_ARG_LENGTH]; |
| 225 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 226 | if (!fgets(buf, sizeof(buf), fp)) break; |
Jin Feng | 93ffa75 | 2013-06-04 17:46:24 +0800 | [diff] [blame] | 227 | token = strtok(buf, "\r\n"); |
| 228 | if (token != NULL) { |
| 229 | (*argv)[*argc] = strdup(token); // Strip newline. |
| 230 | } else { |
| 231 | --*argc; |
| 232 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | check_and_fclose(fp, COMMAND_FILE); |
| 236 | LOGI("Got arguments from %s\n", COMMAND_FILE); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // --> write the arguments we have back into the bootloader control block |
| 241 | // always boot into recovery after this (until finish_recovery() is called) |
| 242 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 243 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 244 | int i; |
| 245 | for (i = 1; i < *argc; ++i) { |
| 246 | strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); |
| 247 | strlcat(boot.recovery, "\n", sizeof(boot.recovery)); |
| 248 | } |
| 249 | set_bootloader_message(&boot); |
| 250 | } |
| 251 | |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 252 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 253 | set_sdcard_update_bootloader_message() { |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 254 | struct bootloader_message boot; |
| 255 | memset(&boot, 0, sizeof(boot)); |
| 256 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 257 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 258 | set_bootloader_message(&boot); |
| 259 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 260 | |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 261 | // How much of the temp log we have copied to the copy in cache. |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 262 | //static long tmplog_offset = 0; |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 263 | |
| 264 | static void |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 265 | copy_log_file(const char* source, const char* destination, int append) { |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 266 | FILE *log = fopen_path(destination, append ? "a" : "w"); |
| 267 | if (log == NULL) { |
| 268 | LOGE("Can't open %s\n", destination); |
| 269 | } else { |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 270 | FILE *tmplog = fopen(source, "r"); |
| 271 | if (tmplog != NULL) { |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 272 | if (append) { |
| 273 | fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write |
| 274 | } |
| 275 | char buf[4096]; |
| 276 | while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log); |
| 277 | if (append) { |
| 278 | tmplog_offset = ftell(tmplog); |
| 279 | } |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 280 | check_and_fclose(tmplog, source); |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 281 | } |
| 282 | check_and_fclose(log, destination); |
| 283 | } |
| 284 | } |
| 285 | |
Doug Zongker | da1ebae | 2013-05-16 11:23:48 -0700 | [diff] [blame] | 286 | // Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max |
| 287 | // Overwrites any existing last_log.$max. |
| 288 | static void |
| 289 | rotate_last_logs(int max) { |
| 290 | char oldfn[256]; |
| 291 | char newfn[256]; |
| 292 | |
| 293 | int i; |
| 294 | for (i = max-1; i >= 0; --i) { |
| 295 | snprintf(oldfn, sizeof(oldfn), (i==0) ? LAST_LOG_FILE : (LAST_LOG_FILE ".%d"), i); |
| 296 | snprintf(newfn, sizeof(newfn), LAST_LOG_FILE ".%d", i+1); |
| 297 | // ignore errors |
| 298 | rename(oldfn, newfn); |
| 299 | } |
| 300 | } |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 301 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 302 | // clear the recovery command and prepare to boot a (hopefully working) system, |
| 303 | // copy our log file to cache as well (for the system to read), and |
| 304 | // record any intent we were asked to communicate back to the system. |
| 305 | // this function is idempotent: call it as many times as you like. |
| 306 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 307 | finish_recovery(const char *send_intent) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 308 | // By this point, we're ready to return to the main system... |
| 309 | if (send_intent != NULL) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 310 | FILE *fp = fopen_path(INTENT_FILE, "w"); |
Jay Freeman (saurik) | 619ec2f | 2008-11-17 01:56:05 +0000 | [diff] [blame] | 311 | if (fp == NULL) { |
| 312 | LOGE("Can't open %s\n", INTENT_FILE); |
| 313 | } else { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 314 | fputs(send_intent, fp); |
| 315 | check_and_fclose(fp, INTENT_FILE); |
| 316 | } |
| 317 | } |
| 318 | |
Doug Zongker | 4f33e55 | 2012-08-23 13:16:12 -0700 | [diff] [blame] | 319 | // Save the locale to cache, so if recovery is next started up |
| 320 | // without a --locale argument (eg, directly from the bootloader) |
| 321 | // it will use the last-known locale. |
| 322 | if (locale != NULL) { |
| 323 | LOGI("Saving locale \"%s\"\n", locale); |
| 324 | FILE* fp = fopen_path(LOCALE_FILE, "w"); |
| 325 | fwrite(locale, 1, strlen(locale), fp); |
| 326 | fflush(fp); |
| 327 | fsync(fileno(fp)); |
| 328 | check_and_fclose(fp, LOCALE_FILE); |
| 329 | } |
| 330 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 331 | // Copy logs to cache so the system can find out what happened. |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 332 | copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true); |
| 333 | copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false); |
| 334 | copy_log_file(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE, false); |
| 335 | chmod(LOG_FILE, 0600); |
| 336 | chown(LOG_FILE, 1000, 1000); // system user |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 337 | chmod(LAST_LOG_FILE, 0640); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 338 | chmod(LAST_INSTALL_FILE, 0644); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 339 | |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 340 | // Reset to normal system boot so recovery won't cycle indefinitely. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 341 | struct bootloader_message boot; |
| 342 | memset(&boot, 0, sizeof(boot)); |
| 343 | set_bootloader_message(&boot); |
| 344 | |
| 345 | // Remove the command file, so recovery won't repeat indefinitely. |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 346 | if (ensure_path_mounted(COMMAND_FILE) != 0 || |
| 347 | (unlink(COMMAND_FILE) && errno != ENOENT)) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 348 | LOGW("Can't unlink %s\n", COMMAND_FILE); |
| 349 | } |
| 350 | |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 351 | ensure_path_unmounted(CACHE_ROOT); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 352 | sync(); // For good measure. |
| 353 | } |
| 354 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 355 | static int |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 356 | erase_volume(const char *volume) { |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 357 | ui->SetBackground(RecoveryUI::ERASING); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 358 | ui->SetProgressType(RecoveryUI::INDETERMINATE); |
| 359 | ui->Print("Formatting %s...\n", volume); |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 360 | |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 361 | ensure_path_unmounted(volume); |
| 362 | |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 363 | if (strcmp(volume, "/cache") == 0) { |
| 364 | // Any part of the log we'd copied to cache is now gone. |
| 365 | // Reset the pointer so we copy from the beginning of the temp |
| 366 | // log. |
| 367 | tmplog_offset = 0; |
| 368 | } |
| 369 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 370 | return format_volume(volume); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 373 | static char* |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 374 | copy_sideloaded_package(const char* original_path) { |
| 375 | if (ensure_path_mounted(original_path) != 0) { |
| 376 | LOGE("Can't mount %s\n", original_path); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 377 | return NULL; |
| 378 | } |
| 379 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 380 | if (ensure_path_mounted(SIDELOAD_TEMP_DIR) != 0) { |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 381 | LOGE("Can't mount %s\n", SIDELOAD_TEMP_DIR); |
| 382 | return NULL; |
| 383 | } |
| 384 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 385 | if (mkdir(SIDELOAD_TEMP_DIR, 0700) != 0) { |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 386 | if (errno != EEXIST) { |
| 387 | LOGE("Can't mkdir %s (%s)\n", SIDELOAD_TEMP_DIR, strerror(errno)); |
| 388 | return NULL; |
| 389 | } |
| 390 | } |
| 391 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 392 | // verify that SIDELOAD_TEMP_DIR is exactly what we expect: a |
| 393 | // directory, owned by root, readable and writable only by root. |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 394 | struct stat st; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 395 | if (stat(SIDELOAD_TEMP_DIR, &st) != 0) { |
| 396 | LOGE("failed to stat %s (%s)\n", SIDELOAD_TEMP_DIR, strerror(errno)); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 397 | return NULL; |
| 398 | } |
| 399 | if (!S_ISDIR(st.st_mode)) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 400 | LOGE("%s isn't a directory\n", SIDELOAD_TEMP_DIR); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 401 | return NULL; |
| 402 | } |
| 403 | if ((st.st_mode & 0777) != 0700) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 404 | LOGE("%s has perms %o\n", SIDELOAD_TEMP_DIR, st.st_mode); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 405 | return NULL; |
| 406 | } |
| 407 | if (st.st_uid != 0) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 408 | LOGE("%s owned by %lu; not root\n", SIDELOAD_TEMP_DIR, st.st_uid); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 409 | return NULL; |
| 410 | } |
| 411 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 412 | char copy_path[PATH_MAX]; |
| 413 | strcpy(copy_path, SIDELOAD_TEMP_DIR); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 414 | strcat(copy_path, "/package.zip"); |
| 415 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 416 | char* buffer = (char*)malloc(BUFSIZ); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 417 | if (buffer == NULL) { |
| 418 | LOGE("Failed to allocate buffer\n"); |
| 419 | return NULL; |
| 420 | } |
| 421 | |
| 422 | size_t read; |
| 423 | FILE* fin = fopen(original_path, "rb"); |
| 424 | if (fin == NULL) { |
| 425 | LOGE("Failed to open %s (%s)\n", original_path, strerror(errno)); |
| 426 | return NULL; |
| 427 | } |
| 428 | FILE* fout = fopen(copy_path, "wb"); |
| 429 | if (fout == NULL) { |
| 430 | LOGE("Failed to open %s (%s)\n", copy_path, strerror(errno)); |
| 431 | return NULL; |
| 432 | } |
| 433 | |
| 434 | while ((read = fread(buffer, 1, BUFSIZ, fin)) > 0) { |
| 435 | if (fwrite(buffer, 1, read, fout) != read) { |
| 436 | LOGE("Short write of %s (%s)\n", copy_path, strerror(errno)); |
| 437 | return NULL; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | free(buffer); |
| 442 | |
| 443 | if (fclose(fout) != 0) { |
| 444 | LOGE("Failed to close %s (%s)\n", copy_path, strerror(errno)); |
| 445 | return NULL; |
| 446 | } |
| 447 | |
| 448 | if (fclose(fin) != 0) { |
| 449 | LOGE("Failed to close %s (%s)\n", original_path, strerror(errno)); |
| 450 | return NULL; |
| 451 | } |
| 452 | |
| 453 | // "adb push" is happy to overwrite read-only files when it's |
| 454 | // running as root, but we'll try anyway. |
| 455 | if (chmod(copy_path, 0400) != 0) { |
| 456 | LOGE("Failed to chmod %s (%s)\n", copy_path, strerror(errno)); |
| 457 | return NULL; |
| 458 | } |
| 459 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 460 | return strdup(copy_path); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 463 | static const char** |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 464 | prepend_title(const char* const* headers) { |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 465 | const char* title[] = { "Android system recovery <" |
| 466 | EXPAND(RECOVERY_API_VERSION) "e>", |
| 467 | "", |
| 468 | NULL }; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 469 | |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 470 | // count the number of lines in our title, plus the |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 471 | // caller-provided headers. |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 472 | int count = 0; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 473 | const char* const* p; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 474 | for (p = title; *p; ++p, ++count); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 475 | for (p = headers; *p; ++p, ++count); |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 476 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 477 | const char** new_headers = (const char**)malloc((count+1) * sizeof(char*)); |
| 478 | const char** h = new_headers; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 479 | for (p = title; *p; ++p, ++h) *h = *p; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 480 | for (p = headers; *p; ++p, ++h) *h = *p; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 481 | *h = NULL; |
| 482 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 483 | return new_headers; |
| 484 | } |
| 485 | |
| 486 | static int |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 487 | get_menu_selection(const char* const * headers, const char* const * items, |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 488 | int menu_only, int initial_selection, Device* device) { |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 489 | // throw away keys pressed previously, so user doesn't |
| 490 | // accidentally trigger menu items. |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 491 | ui->FlushKeys(); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 492 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 493 | ui->StartMenu(headers, items, initial_selection); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 494 | int selected = initial_selection; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 495 | int chosen_item = -1; |
| 496 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 497 | while (chosen_item < 0) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 498 | int key = ui->WaitKey(); |
| 499 | int visible = ui->IsTextVisible(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 500 | |
Doug Zongker | 5cae445 | 2011-01-25 13:15:30 -0800 | [diff] [blame] | 501 | if (key == -1) { // ui_wait_key() timed out |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 502 | if (ui->WasTextEverVisible()) { |
Doug Zongker | 5cae445 | 2011-01-25 13:15:30 -0800 | [diff] [blame] | 503 | continue; |
| 504 | } else { |
| 505 | LOGI("timed out waiting for key input; rebooting.\n"); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 506 | ui->EndMenu(); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 507 | return 0; // XXX fixme |
Doug Zongker | 5cae445 | 2011-01-25 13:15:30 -0800 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 511 | int action = device->HandleMenuKey(key, visible); |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 512 | |
| 513 | if (action < 0) { |
| 514 | switch (action) { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 515 | case Device::kHighlightUp: |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 516 | --selected; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 517 | selected = ui->SelectMenu(selected); |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 518 | break; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 519 | case Device::kHighlightDown: |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 520 | ++selected; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 521 | selected = ui->SelectMenu(selected); |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 522 | break; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 523 | case Device::kInvokeItem: |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 524 | chosen_item = selected; |
| 525 | break; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 526 | case Device::kNoAction: |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 527 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 528 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 529 | } else if (!menu_only) { |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 530 | chosen_item = action; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 531 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 532 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 533 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 534 | ui->EndMenu(); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 535 | return chosen_item; |
| 536 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 537 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 538 | static int compare_string(const void* a, const void* b) { |
| 539 | return strcmp(*(const char**)a, *(const char**)b); |
| 540 | } |
| 541 | |
| 542 | static int |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 543 | update_directory(const char* path, const char* unmount_when_done, |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 544 | int* wipe_cache, Device* device) { |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 545 | ensure_path_mounted(path); |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 546 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 547 | const char* MENU_HEADERS[] = { "Choose a package to install:", |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 548 | path, |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 549 | "", |
| 550 | NULL }; |
| 551 | DIR* d; |
| 552 | struct dirent* de; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 553 | d = opendir(path); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 554 | if (d == NULL) { |
| 555 | LOGE("error opening %s: %s\n", path, strerror(errno)); |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 556 | if (unmount_when_done != NULL) { |
| 557 | ensure_path_unmounted(unmount_when_done); |
| 558 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 562 | const char** headers = prepend_title(MENU_HEADERS); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 563 | |
| 564 | int d_size = 0; |
| 565 | int d_alloc = 10; |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 566 | char** dirs = (char**)malloc(d_alloc * sizeof(char*)); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 567 | int z_size = 1; |
| 568 | int z_alloc = 10; |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 569 | char** zips = (char**)malloc(z_alloc * sizeof(char*)); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 570 | zips[0] = strdup("../"); |
| 571 | |
| 572 | while ((de = readdir(d)) != NULL) { |
| 573 | int name_len = strlen(de->d_name); |
| 574 | |
| 575 | if (de->d_type == DT_DIR) { |
| 576 | // skip "." and ".." entries |
| 577 | if (name_len == 1 && de->d_name[0] == '.') continue; |
| 578 | if (name_len == 2 && de->d_name[0] == '.' && |
| 579 | de->d_name[1] == '.') continue; |
| 580 | |
| 581 | if (d_size >= d_alloc) { |
| 582 | d_alloc *= 2; |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 583 | dirs = (char**)realloc(dirs, d_alloc * sizeof(char*)); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 584 | } |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 585 | dirs[d_size] = (char*)malloc(name_len + 2); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 586 | strcpy(dirs[d_size], de->d_name); |
| 587 | dirs[d_size][name_len] = '/'; |
| 588 | dirs[d_size][name_len+1] = '\0'; |
| 589 | ++d_size; |
| 590 | } else if (de->d_type == DT_REG && |
| 591 | name_len >= 4 && |
| 592 | strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) { |
| 593 | if (z_size >= z_alloc) { |
| 594 | z_alloc *= 2; |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 595 | zips = (char**)realloc(zips, z_alloc * sizeof(char*)); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 596 | } |
| 597 | zips[z_size++] = strdup(de->d_name); |
| 598 | } |
| 599 | } |
| 600 | closedir(d); |
| 601 | |
| 602 | qsort(dirs, d_size, sizeof(char*), compare_string); |
| 603 | qsort(zips, z_size, sizeof(char*), compare_string); |
| 604 | |
| 605 | // append dirs to the zips list |
| 606 | if (d_size + z_size + 1 > z_alloc) { |
| 607 | z_alloc = d_size + z_size + 1; |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 608 | zips = (char**)realloc(zips, z_alloc * sizeof(char*)); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 609 | } |
| 610 | memcpy(zips + z_size, dirs, d_size * sizeof(char*)); |
| 611 | free(dirs); |
| 612 | z_size += d_size; |
| 613 | zips[z_size] = NULL; |
| 614 | |
| 615 | int result; |
| 616 | int chosen_item = 0; |
| 617 | do { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 618 | chosen_item = get_menu_selection(headers, zips, 1, chosen_item, device); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 619 | |
| 620 | char* item = zips[chosen_item]; |
| 621 | int item_len = strlen(item); |
| 622 | if (chosen_item == 0) { // item 0 is always "../" |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 623 | // go up but continue browsing (if the caller is update_directory) |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 624 | result = -1; |
| 625 | break; |
| 626 | } else if (item[item_len-1] == '/') { |
| 627 | // recurse down into a subdirectory |
| 628 | char new_path[PATH_MAX]; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 629 | strlcpy(new_path, path, PATH_MAX); |
| 630 | strlcat(new_path, "/", PATH_MAX); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 631 | strlcat(new_path, item, PATH_MAX); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 632 | new_path[strlen(new_path)-1] = '\0'; // truncate the trailing '/' |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 633 | result = update_directory(new_path, unmount_when_done, wipe_cache, device); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 634 | if (result >= 0) break; |
| 635 | } else { |
| 636 | // selected a zip file: attempt to install it, and return |
| 637 | // the status to the caller. |
| 638 | char new_path[PATH_MAX]; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 639 | strlcpy(new_path, path, PATH_MAX); |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 640 | strlcat(new_path, "/", PATH_MAX); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 641 | strlcat(new_path, item, PATH_MAX); |
| 642 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 643 | ui->Print("\n-- Install %s ...\n", path); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 644 | set_sdcard_update_bootloader_message(); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 645 | char* copy = copy_sideloaded_package(new_path); |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 646 | if (unmount_when_done != NULL) { |
| 647 | ensure_path_unmounted(unmount_when_done); |
| 648 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 649 | if (copy) { |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 650 | result = install_package(copy, wipe_cache, TEMPORARY_INSTALL_FILE); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 651 | free(copy); |
| 652 | } else { |
| 653 | result = INSTALL_ERROR; |
| 654 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 655 | break; |
| 656 | } |
| 657 | } while (true); |
| 658 | |
| 659 | int i; |
| 660 | for (i = 0; i < z_size; ++i) free(zips[i]); |
| 661 | free(zips); |
| 662 | free(headers); |
| 663 | |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 664 | if (unmount_when_done != NULL) { |
| 665 | ensure_path_unmounted(unmount_when_done); |
| 666 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 667 | return result; |
| 668 | } |
| 669 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 670 | static void |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 671 | wipe_data(int confirm, Device* device) { |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 672 | if (confirm) { |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 673 | static const char** title_headers = NULL; |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 674 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 675 | if (title_headers == NULL) { |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 676 | const char* headers[] = { "Confirm wipe of all user data?", |
| 677 | " THIS CAN NOT BE UNDONE.", |
| 678 | "", |
| 679 | NULL }; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 680 | title_headers = prepend_title((const char**)headers); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 681 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 682 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 683 | const char* items[] = { " No", |
| 684 | " No", |
| 685 | " No", |
| 686 | " No", |
| 687 | " No", |
| 688 | " No", |
| 689 | " No", |
| 690 | " Yes -- delete all user data", // [7] |
| 691 | " No", |
| 692 | " No", |
| 693 | " No", |
| 694 | NULL }; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 695 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 696 | int chosen_item = get_menu_selection(title_headers, items, 1, 0, device); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 697 | if (chosen_item != 7) { |
| 698 | return; |
| 699 | } |
| 700 | } |
Doug Zongker | 1066d2c | 2009-04-01 13:57:40 -0700 | [diff] [blame] | 701 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 702 | ui->Print("\n-- Wiping data...\n"); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 703 | device->WipeData(); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 704 | erase_volume("/data"); |
| 705 | erase_volume("/cache"); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 706 | ui->Print("Data wipe complete.\n"); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static void |
Doug Zongker | 6c8553d | 2012-09-24 10:40:47 -0700 | [diff] [blame] | 710 | prompt_and_wait(Device* device, int status) { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 711 | const char* const* headers = prepend_title(device->GetMenuHeaders()); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 712 | |
| 713 | for (;;) { |
| 714 | finish_recovery(NULL); |
Doug Zongker | 6c8553d | 2012-09-24 10:40:47 -0700 | [diff] [blame] | 715 | switch (status) { |
| 716 | case INSTALL_SUCCESS: |
| 717 | case INSTALL_NONE: |
| 718 | ui->SetBackground(RecoveryUI::NO_COMMAND); |
| 719 | break; |
| 720 | |
| 721 | case INSTALL_ERROR: |
| 722 | case INSTALL_CORRUPT: |
| 723 | ui->SetBackground(RecoveryUI::ERROR); |
| 724 | break; |
| 725 | } |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 726 | ui->SetProgressType(RecoveryUI::EMPTY); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 727 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 728 | int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 729 | |
| 730 | // device-specific code may take some action here. It may |
| 731 | // return one of the core actions handled in the switch |
| 732 | // statement below. |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 733 | chosen_item = device->InvokeMenuItem(chosen_item); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 734 | |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 735 | int wipe_cache; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 736 | switch (chosen_item) { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 737 | case Device::REBOOT: |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 738 | return; |
| 739 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 740 | case Device::WIPE_DATA: |
| 741 | wipe_data(ui->IsTextVisible(), device); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 742 | if (!ui->IsTextVisible()) return; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 745 | case Device::WIPE_CACHE: |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 746 | ui->Print("\n-- Wiping cache...\n"); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 747 | erase_volume("/cache"); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 748 | ui->Print("Cache wipe complete.\n"); |
| 749 | if (!ui->IsTextVisible()) return; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 750 | break; |
| 751 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 752 | case Device::APPLY_EXT: |
Doug Zongker | d9428e3 | 2011-12-13 16:03:28 -0800 | [diff] [blame] | 753 | // Some packages expect /cache to be mounted (eg, |
| 754 | // standard incremental packages expect to use /cache |
| 755 | // as scratch space). |
| 756 | ensure_path_mounted(CACHE_ROOT); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 757 | status = update_directory(SDCARD_ROOT, SDCARD_ROOT, &wipe_cache, device); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 758 | if (status == INSTALL_SUCCESS && wipe_cache) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 759 | ui->Print("\n-- Wiping cache (at package request)...\n"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 760 | if (erase_volume("/cache")) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 761 | ui->Print("Cache wipe failed.\n"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 762 | } else { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 763 | ui->Print("Cache wipe complete.\n"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 766 | if (status >= 0) { |
| 767 | if (status != INSTALL_SUCCESS) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 768 | ui->SetBackground(RecoveryUI::ERROR); |
| 769 | ui->Print("Installation aborted.\n"); |
| 770 | } else if (!ui->IsTextVisible()) { |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 771 | return; // reboot if logs aren't visible |
| 772 | } else { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 773 | ui->Print("\nInstall from sdcard complete.\n"); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 774 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 775 | } |
| 776 | break; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 777 | |
| 778 | case Device::APPLY_CACHE: |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 779 | // Don't unmount cache at the end of this. |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 780 | status = update_directory(CACHE_ROOT, NULL, &wipe_cache, device); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 781 | if (status == INSTALL_SUCCESS && wipe_cache) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 782 | ui->Print("\n-- Wiping cache (at package request)...\n"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 783 | if (erase_volume("/cache")) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 784 | ui->Print("Cache wipe failed.\n"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 785 | } else { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 786 | ui->Print("Cache wipe complete.\n"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 789 | if (status >= 0) { |
| 790 | if (status != INSTALL_SUCCESS) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 791 | ui->SetBackground(RecoveryUI::ERROR); |
| 792 | ui->Print("Installation aborted.\n"); |
| 793 | } else if (!ui->IsTextVisible()) { |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 794 | return; // reboot if logs aren't visible |
| 795 | } else { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 796 | ui->Print("\nInstall from cache complete.\n"); |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | break; |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 800 | |
| 801 | case Device::APPLY_ADB_SIDELOAD: |
| 802 | ensure_path_mounted(CACHE_ROOT); |
| 803 | status = apply_from_adb(ui, &wipe_cache, TEMPORARY_INSTALL_FILE); |
| 804 | if (status >= 0) { |
| 805 | if (status != INSTALL_SUCCESS) { |
| 806 | ui->SetBackground(RecoveryUI::ERROR); |
| 807 | ui->Print("Installation aborted.\n"); |
| 808 | } else if (!ui->IsTextVisible()) { |
| 809 | return; // reboot if logs aren't visible |
| 810 | } else { |
| 811 | ui->Print("\nInstall from ADB complete.\n"); |
| 812 | } |
| 813 | } |
| 814 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 820 | print_property(const char *key, const char *name, void *cookie) { |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 821 | printf("%s=%s\n", key, name); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 822 | } |
| 823 | |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 824 | static void |
| 825 | load_locale_from_cache() { |
| 826 | FILE* fp = fopen_path(LOCALE_FILE, "r"); |
| 827 | char buffer[80]; |
| 828 | if (fp != NULL) { |
| 829 | fgets(buffer, sizeof(buffer), fp); |
| 830 | int j = 0; |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 831 | unsigned int i; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 832 | for (i = 0; i < sizeof(buffer) && buffer[i]; ++i) { |
| 833 | if (!isspace(buffer[i])) { |
| 834 | buffer[j++] = buffer[i]; |
| 835 | } |
| 836 | } |
| 837 | buffer[j] = 0; |
| 838 | locale = strdup(buffer); |
Devin Kim | 6016d08 | 2012-10-08 09:47:37 -0700 | [diff] [blame] | 839 | check_and_fclose(fp, LOCALE_FILE); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 843 | static RecoveryUI* gCurrentUI = NULL; |
| 844 | |
| 845 | void |
| 846 | ui_print(const char* format, ...) { |
| 847 | char buffer[256]; |
| 848 | |
| 849 | va_list ap; |
| 850 | va_start(ap, format); |
| 851 | vsnprintf(buffer, sizeof(buffer), format, ap); |
| 852 | va_end(ap); |
| 853 | |
| 854 | if (gCurrentUI != NULL) { |
| 855 | gCurrentUI->Print("%s", buffer); |
| 856 | } else { |
| 857 | fputs(buffer, stdout); |
| 858 | } |
| 859 | } |
| 860 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 861 | int |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 862 | main(int argc, char **argv) { |
Dees_Troy | cfb63ae | 2012-09-19 14:30:17 -0400 | [diff] [blame] | 863 | // Recovery needs to install world-readable files, so clear umask |
| 864 | // set by init |
| 865 | umask(0); |
| 866 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 867 | time_t start = time(NULL); |
| 868 | |
| 869 | // If these fail, there's not really anywhere to complain... |
| 870 | freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); |
| 871 | freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 872 | |
| 873 | // If this binary is started with the single argument "--adbd", |
| 874 | // instead of being the normal recovery binary, it turns into kind |
| 875 | // of a stripped-down version of adbd that only supports the |
| 876 | // 'sideload' command. Note this must be a real argument, not |
| 877 | // anything in the command file or bootloader control block; the |
| 878 | // only way recovery should be run with this argument is when it |
| 879 | // starts a copy of itself from the apply_from_adb() function. |
Dees_Troy | 9a4b569 | 2012-09-19 15:09:45 -0400 | [diff] [blame] | 880 | if (argc == 3 && strcmp(argv[1], "--adbd") == 0) { |
| 881 | adb_main(argv[2]); |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 882 | return 0; |
| 883 | } |
| 884 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 885 | printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&start)); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 886 | |
Dees_Troy | 32c8eb8 | 2012-09-11 15:28:06 -0400 | [diff] [blame] | 887 | Device* device = make_device(); |
| 888 | ui = device->GetUI(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 889 | |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 890 | //ui->Init(); |
| 891 | //ui->SetBackground(RecoveryUI::NONE); |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 892 | //load_volume_table(); |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 893 | |
| 894 | // Load default values to set DataManager constants and handle ifdefs |
| 895 | DataManager_LoadDefaults(); |
| 896 | printf("Starting the UI..."); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 897 | gui_init(); |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 898 | printf("=> Linking mtab\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 899 | symlink("/proc/mounts", "/etc/mtab"); |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 900 | printf("=> Processing recovery.fstab\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 901 | if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) { |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 902 | LOGE("Failing out of recovery due to problem with recovery.fstab.\n"); |
| 903 | //return -1; |
| 904 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 905 | PartitionManager.Output_Partition_Logging(); |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 906 | // Load up all the resources |
| 907 | gui_loadResources(); |
| 908 | |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 909 | PartitionManager.Mount_By_Path("/cache", true); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 910 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 911 | load_volume_table(); |
Doug Zongker | da1ebae | 2013-05-16 11:23:48 -0700 | [diff] [blame] | 912 | ensure_path_mounted(LAST_LOG_FILE); |
| 913 | rotate_last_logs(5); |
Dees_Troy | 1669f89 | 2013-09-04 18:35:08 +0000 | [diff] [blame] | 914 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 915 | get_args(&argc, &argv); |
| 916 | |
| 917 | int previous_runs = 0; |
| 918 | const char *send_intent = NULL; |
| 919 | const char *update_package = NULL; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 920 | int wipe_data = 0, wipe_cache = 0, show_text = 0; |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 921 | bool just_exit = false; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 922 | bool perform_backup = false; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 923 | |
| 924 | int arg; |
| 925 | while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { |
| 926 | switch (arg) { |
| 927 | case 'p': previous_runs = atoi(optarg); break; |
| 928 | case 's': send_intent = optarg; break; |
| 929 | case 'u': update_package = optarg; break; |
| 930 | case 'w': wipe_data = wipe_cache = 1; break; |
| 931 | case 'c': wipe_cache = 1; break; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 932 | case 't': show_text = 1; break; |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 933 | case 'x': just_exit = true; break; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 934 | case 'l': locale = optarg; break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 935 | case '?': |
| 936 | LOGE("Invalid command argument\n"); |
| 937 | continue; |
| 938 | } |
| 939 | } |
| 940 | |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 941 | if (locale == NULL) { |
| 942 | load_locale_from_cache(); |
| 943 | } |
| 944 | printf("locale is [%s]\n", locale); |
| 945 | |
| 946 | Device* device = make_device(); |
| 947 | ui = device->GetUI(); |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 948 | gCurrentUI = ui; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 949 | |
| 950 | ui->Init(); |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 951 | ui->SetLocale(locale); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 952 | ui->SetBackground(RecoveryUI::NONE); |
| 953 | if (show_text) ui->ShowText(true); |
| 954 | |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 955 | struct selinux_opt seopts[] = { |
| 956 | { SELABEL_OPT_PATH, "/file_contexts" } |
| 957 | }; |
| 958 | |
| 959 | sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); |
| 960 | |
| 961 | if (!sehandle) { |
| 962 | fprintf(stderr, "Warning: No file_contexts\n"); |
Kenny Root | 038818c | 2012-04-08 11:03:01 -0700 | [diff] [blame] | 963 | ui->Print("Warning: No file_contexts\n"); |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 964 | } |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 965 | |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 966 | //device->StartRecovery(); |
Doug Zongker | efa1bab | 2010-02-01 15:59:12 -0800 | [diff] [blame] | 967 | |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 968 | printf("Command:"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 969 | for (arg = 0; arg < argc; arg++) { |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 970 | printf(" \"%s\"", argv[arg]); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 971 | } |
Doug Zongker | 9b125b0 | 2010-09-22 12:01:37 -0700 | [diff] [blame] | 972 | printf("\n"); |
| 973 | |
| 974 | if (update_package) { |
| 975 | // For backwards compatibility on the cache partition only, if |
| 976 | // we're given an old 'root' path "CACHE:foo", change it to |
| 977 | // "/cache/foo". |
| 978 | if (strncmp(update_package, "CACHE:", 6) == 0) { |
| 979 | int len = strlen(update_package) + 10; |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 980 | char* modified_path = (char*)malloc(len); |
Doug Zongker | 9b125b0 | 2010-09-22 12:01:37 -0700 | [diff] [blame] | 981 | strlcpy(modified_path, "/cache/", len); |
| 982 | strlcat(modified_path, update_package+6, len); |
| 983 | printf("(replacing path \"%s\" with \"%s\")\n", |
| 984 | update_package, modified_path); |
| 985 | update_package = modified_path; |
| 986 | } |
| 987 | } |
| 988 | printf("\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 989 | |
| 990 | property_list(print_property, NULL); |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 991 | printf("\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 992 | |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 993 | // Check for and run startup script if script exists |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 994 | TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot"); |
| 995 | TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot"); |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 996 | |
| 997 | #ifdef TW_INCLUDE_INJECTTWRP |
| 998 | // Back up TWRP Ramdisk if needed: |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 999 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 1000 | LOGI("Backing up TWRP ramdisk...\n"); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 1001 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 1002 | TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img"); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 1003 | else { |
| 1004 | 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] | 1005 | TWFunc::Exec_Cmd(injectcmd); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 1006 | } |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 1007 | LOGI("Backup of TWRP ramdisk done.\n"); |
| 1008 | #endif |
| 1009 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1010 | int status = INSTALL_SUCCESS; |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 1011 | string ORSCommand; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1012 | |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 1013 | if (perform_backup) { |
| 1014 | char empt[50]; |
| 1015 | gui_console_only(); |
| 1016 | strcpy(empt, "(Current Date)"); |
| 1017 | DataManager_SetStrValue(TW_BACKUP_NAME, empt); |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 1018 | if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n")) |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 1019 | status = INSTALL_ERROR; |
| 1020 | } |
| 1021 | if (status == INSTALL_SUCCESS) { // Prevent other actions if backup failed |
Doug Zongker | 540d57f | 2011-01-18 13:36:58 -0800 | [diff] [blame] | 1022 | if (update_package != NULL) { |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 1023 | ORSCommand = "install "; |
| 1024 | ORSCommand += update_package; |
| 1025 | ORSCommand += "\n"; |
| 1026 | |
| 1027 | if (OpenRecoveryScript::Insert_ORS_Command(ORSCommand)) |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 1028 | status = INSTALL_SUCCESS; |
| 1029 | else |
| 1030 | status = INSTALL_ERROR; |
| 1031 | /* |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 1032 | status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE); |
| 1033 | if (status == INSTALL_SUCCESS && wipe_cache) { |
| 1034 | if (erase_volume("/cache")) { |
| 1035 | LOGE("Cache wipe (requested by package) failed."); |
| 1036 | } |
| 1037 | } |
Dees_Troy | 1669f89 | 2013-09-04 18:35:08 +0000 | [diff] [blame] | 1038 | |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 1039 | if (status != INSTALL_SUCCESS) { |
| 1040 | ui->Print("Installation aborted.\n"); |
| 1041 | |
| 1042 | // If this is an eng or userdebug build, then automatically |
| 1043 | // turn the text display on if the script fails so the error |
| 1044 | // message is visible. |
| 1045 | char buffer[PROPERTY_VALUE_MAX+1]; |
| 1046 | property_get("ro.build.fingerprint", buffer, ""); |
| 1047 | if (strstr(buffer, ":userdebug/") || strstr(buffer, ":eng/")) { |
| 1048 | ui->ShowText(true); |
| 1049 | } |
| 1050 | } |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 1051 | } else if (wipe_data) { |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 1052 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n")) |
| 1053 | status = INSTALL_ERROR; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 1054 | /* |
| 1055 | if (device->WipeData()) status = INSTALL_ERROR; |
| 1056 | if (erase_volume("/data")) status = INSTALL_ERROR; |
| 1057 | if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; |
| 1058 | */ |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 1059 | if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 1060 | } else if (wipe_cache) { |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 1061 | if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n")) |
| 1062 | status = INSTALL_ERROR; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 1063 | if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 1064 | } else if (!just_exit) { |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 1065 | status = INSTALL_NONE; // No command specified |
| 1066 | ui->SetBackground(RecoveryUI::NO_COMMAND); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1067 | } |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 1068 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1069 | |
Dees_Troy | d15e3f7 | 2013-02-21 14:28:29 -0600 | [diff] [blame] | 1070 | finish_recovery(NULL); |
| 1071 | // Offer to decrypt if the device is encrypted |
| 1072 | if (DataManager_GetIntValue(TW_IS_ENCRYPTED) != 0) { |
| 1073 | LOGI("Is encrypted, do decrypt page first\n"); |
| 1074 | if (gui_startPage("decrypt") != 0) { |
| 1075 | LOGE("Failed to start decrypt GUI page.\n"); |
Dees_Troy | c7c4341 | 2012-10-02 23:03:01 -0400 | [diff] [blame] | 1076 | } |
Dees_Troy | d15e3f7 | 2013-02-21 14:28:29 -0600 | [diff] [blame] | 1077 | } |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 1078 | |
Dees_Troy | d15e3f7 | 2013-02-21 14:28:29 -0600 | [diff] [blame] | 1079 | // Read the settings file |
| 1080 | DataManager_ReadSettingsFile(); |
| 1081 | // Run any outstanding OpenRecoveryScript |
| 1082 | if (DataManager_GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) { |
| 1083 | OpenRecoveryScript::Run_OpenRecoveryScript(); |
| 1084 | } |
| 1085 | // Launch the main GUI |
| 1086 | gui_start(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1087 | |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 1088 | // Check for su to see if the device is rooted or not |
| 1089 | if (PartitionManager.Mount_By_Path("/system", false)) { |
Dees_Troy | d15e3f7 | 2013-02-21 14:28:29 -0600 | [diff] [blame] | 1090 | // Disable flashing of stock recovery |
| 1091 | if (TWFunc::Path_Exists("/system/recovery-from-boot.p")) { |
| 1092 | rename("/system/recovery-from-boot.p", "/system/recovery-from-boot.bak"); |
| 1093 | ui_print("Renamed stock recovery file in /system to prevent\nthe stock ROM from replacing TWRP.\n"); |
| 1094 | } |
jt1134 | 113ee73 | 2013-02-22 23:26:10 -0600 | [diff] [blame] | 1095 | 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")) { |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 1096 | // Device doesn't have su installed |
| 1097 | DataManager_SetIntValue("tw_busy", 1); |
| 1098 | if (gui_startPage("installsu") != 0) { |
| 1099 | LOGE("Failed to start decrypt GUI page.\n"); |
| 1100 | } |
| 1101 | } else if (TWFunc::Check_su_Perms() > 0) { |
| 1102 | // su perms are set incorrectly |
| 1103 | DataManager_SetIntValue("tw_busy", 1); |
| 1104 | if (gui_startPage("fixsu") != 0) { |
| 1105 | LOGE("Failed to start decrypt GUI page.\n"); |
| 1106 | } |
| 1107 | } |
Dees_Troy | d15e3f7 | 2013-02-21 14:28:29 -0600 | [diff] [blame] | 1108 | sync(); |
| 1109 | PartitionManager.UnMount_By_Path("/system", false); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 1110 | } |
| 1111 | |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 1112 | if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) { |
| 1113 | ui->SetBackground(RecoveryUI::ERROR); |
| 1114 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1115 | if (status != INSTALL_SUCCESS || ui->IsTextVisible()) { |
Doug Zongker | 6c8553d | 2012-09-24 10:40:47 -0700 | [diff] [blame] | 1116 | prompt_and_wait(device, status); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | // Otherwise, get ready to boot the main system... |
| 1120 | finish_recovery(send_intent); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 1121 | ui->Print("Rebooting...\n"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 1122 | char backup_arg_char[50]; |
| 1123 | strcpy(backup_arg_char, DataManager_GetStrValue("tw_reboot_arg")); |
| 1124 | string backup_arg = backup_arg_char; |
| 1125 | if (backup_arg == "recovery") |
| 1126 | TWFunc::tw_reboot(rb_recovery); |
| 1127 | else if (backup_arg == "poweroff") |
| 1128 | TWFunc::tw_reboot(rb_poweroff); |
| 1129 | else if (backup_arg == "bootloader") |
| 1130 | TWFunc::tw_reboot(rb_bootloader); |
| 1131 | else if (backup_arg == "download") |
| 1132 | TWFunc::tw_reboot(rb_download); |
| 1133 | else |
| 1134 | TWFunc::tw_reboot(rb_system); |
| 1135 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1136 | #ifdef ANDROID_RB_RESTART |
Ken Sumrall | 6e4472a | 2011-03-07 23:37:27 -0800 | [diff] [blame] | 1137 | android_reboot(ANDROID_RB_RESTART, 0, 0); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1138 | #else |
| 1139 | reboot(RB_AUTOBOOT); |
| 1140 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1141 | return EXIT_SUCCESS; |
| 1142 | } |