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> |
| 18 | #include <errno.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <getopt.h> |
| 21 | #include <limits.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <sys/reboot.h> |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 27 | #include <sys/stat.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 28 | #include <sys/types.h> |
| 29 | #include <time.h> |
| 30 | #include <unistd.h> |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 31 | #include <dirent.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 36 | #include "install.h" |
| 37 | #include "minui/minui.h" |
| 38 | #include "minzip/DirUtil.h" |
| 39 | #include "roots.h" |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 40 | #include "recovery_ui.h" |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 41 | #include "encryptedfs_provisioning.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 42 | |
| 43 | static const struct option OPTIONS[] = { |
| 44 | { "send_intent", required_argument, NULL, 's' }, |
| 45 | { "update_package", required_argument, NULL, 'u' }, |
| 46 | { "wipe_data", no_argument, NULL, 'w' }, |
| 47 | { "wipe_cache", no_argument, NULL, 'c' }, |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 48 | { "set_encrypted_filesystems", required_argument, NULL, 'e' }, |
Doug Zongker | 4bc9806 | 2010-09-03 11:00:13 -0700 | [diff] [blame] | 49 | { "show_text", no_argument, NULL, 't' }, |
Doug Zongker | 988500b | 2009-10-06 14:41:38 -0700 | [diff] [blame] | 50 | { NULL, 0, NULL, 0 }, |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | static const char *COMMAND_FILE = "CACHE:recovery/command"; |
| 54 | static const char *INTENT_FILE = "CACHE:recovery/intent"; |
| 55 | static const char *LOG_FILE = "CACHE:recovery/log"; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 56 | static const char *SDCARD_ROOT = "SDCARD:"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 57 | static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 58 | static const char *SIDELOAD_TEMP_DIR = "TMP:sideload"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * The recovery tool communicates with the main system through /cache files. |
| 62 | * /cache/recovery/command - INPUT - command line for tool, one arg per line |
| 63 | * /cache/recovery/log - OUTPUT - combined log file from recovery run(s) |
| 64 | * /cache/recovery/intent - OUTPUT - intent that was passed in |
| 65 | * |
| 66 | * The arguments which may be supplied in the recovery.command file: |
| 67 | * --send_intent=anystring - write the text out to recovery.intent |
| 68 | * --update_package=root:path - verify install an OTA package file |
| 69 | * --wipe_data - erase user data (and cache), then reboot |
| 70 | * --wipe_cache - wipe cache (but not user data), then reboot |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 71 | * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 72 | * |
| 73 | * After completing, we remove /cache/recovery/command and reboot. |
| 74 | * Arguments may also be supplied in the bootloader control block (BCB). |
| 75 | * These important scenarios must be safely restartable at any point: |
| 76 | * |
| 77 | * FACTORY RESET |
| 78 | * 1. user selects "factory reset" |
| 79 | * 2. main system writes "--wipe_data" to /cache/recovery/command |
| 80 | * 3. main system reboots into recovery |
| 81 | * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data" |
| 82 | * -- after this, rebooting will restart the erase -- |
| 83 | * 5. erase_root() reformats /data |
| 84 | * 6. erase_root() reformats /cache |
| 85 | * 7. finish_recovery() erases BCB |
| 86 | * -- after this, rebooting will restart the main system -- |
| 87 | * 8. main() calls reboot() to boot main system |
| 88 | * |
| 89 | * OTA INSTALL |
| 90 | * 1. main system downloads OTA package to /cache/some-filename.zip |
| 91 | * 2. main system writes "--update_package=CACHE:some-filename.zip" |
| 92 | * 3. main system reboots into recovery |
| 93 | * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..." |
| 94 | * -- after this, rebooting will attempt to reinstall the update -- |
| 95 | * 5. install_package() attempts to install the update |
| 96 | * NOTE: the package install must itself be restartable from any point |
| 97 | * 6. finish_recovery() erases BCB |
| 98 | * -- after this, rebooting will (try to) restart the main system -- |
| 99 | * 7. ** if install failed ** |
| 100 | * 7a. prompt_and_wait() shows an error icon and waits for the user |
| 101 | * 7b; the user reboots (pulling the battery, etc) into the main system |
| 102 | * 8. main() calls maybe_install_firmware_update() |
| 103 | * ** if the update contained radio/hboot firmware **: |
| 104 | * 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache" |
| 105 | * -- after this, rebooting will reformat cache & restart main system -- |
| 106 | * 8b. m_i_f_u() writes firmware image into raw cache partition |
| 107 | * 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache" |
| 108 | * -- after this, rebooting will attempt to reinstall firmware -- |
| 109 | * 8d. bootloader tries to flash firmware |
| 110 | * 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache") |
| 111 | * -- after this, rebooting will reformat cache & restart main system -- |
| 112 | * 8f. erase_root() reformats /cache |
| 113 | * 8g. finish_recovery() erases BCB |
| 114 | * -- after this, rebooting will (try to) restart the main system -- |
| 115 | * 9. main() calls reboot() to boot main system |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 116 | * |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 117 | * SECURE FILE SYSTEMS ENABLE/DISABLE |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 118 | * 1. user selects "enable encrypted file systems" |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 119 | * 2. main system writes "--set_encrypted_filesystems=on|off" to |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 120 | * /cache/recovery/command |
| 121 | * 3. main system reboots into recovery |
| 122 | * 4. get_args() writes BCB with "boot-recovery" and |
| 123 | * "--set_encrypted_filesystems=on|off" |
| 124 | * -- after this, rebooting will restart the transition -- |
| 125 | * 5. read_encrypted_fs_info() retrieves encrypted file systems settings from /data |
| 126 | * Settings include: property to specify the Encrypted FS istatus and |
| 127 | * FS encryption key if enabled (not yet implemented) |
| 128 | * 6. erase_root() reformats /data |
| 129 | * 7. erase_root() reformats /cache |
| 130 | * 8. restore_encrypted_fs_info() writes required encrypted file systems settings to /data |
| 131 | * Settings include: property to specify the Encrypted FS status and |
| 132 | * FS encryption key if enabled (not yet implemented) |
| 133 | * 9. finish_recovery() erases BCB |
| 134 | * -- after this, rebooting will restart the main system -- |
| 135 | * 10. main() calls reboot() to boot main system |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 136 | */ |
| 137 | |
| 138 | static const int MAX_ARG_LENGTH = 4096; |
| 139 | static const int MAX_ARGS = 100; |
| 140 | |
| 141 | // open a file given in root:path format, mounting partitions as necessary |
| 142 | static FILE* |
| 143 | fopen_root_path(const char *root_path, const char *mode) { |
| 144 | if (ensure_root_path_mounted(root_path) != 0) { |
| 145 | LOGE("Can't mount %s\n", root_path); |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | char path[PATH_MAX] = ""; |
| 150 | if (translate_root_path(root_path, path, sizeof(path)) == NULL) { |
| 151 | LOGE("Bad path %s\n", root_path); |
| 152 | return NULL; |
| 153 | } |
| 154 | |
| 155 | // When writing, try to create the containing directory, if necessary. |
| 156 | // Use generous permissions, the system (init.rc) will reset them. |
| 157 | if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1); |
| 158 | |
| 159 | FILE *fp = fopen(path, mode); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 160 | return fp; |
| 161 | } |
| 162 | |
| 163 | // close a file, log an error if the error indicator is set |
| 164 | static void |
| 165 | check_and_fclose(FILE *fp, const char *name) { |
| 166 | fflush(fp); |
| 167 | if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno)); |
| 168 | fclose(fp); |
| 169 | } |
| 170 | |
| 171 | // command line args come from, in decreasing precedence: |
| 172 | // - the actual command line |
| 173 | // - the bootloader control block (one per line, after "recovery") |
| 174 | // - the contents of COMMAND_FILE (one per line) |
| 175 | static void |
| 176 | get_args(int *argc, char ***argv) { |
| 177 | struct bootloader_message boot; |
| 178 | memset(&boot, 0, sizeof(boot)); |
| 179 | get_bootloader_message(&boot); // this may fail, leaving a zeroed structure |
| 180 | |
| 181 | if (boot.command[0] != 0 && boot.command[0] != 255) { |
| 182 | LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command); |
| 183 | } |
| 184 | |
| 185 | if (boot.status[0] != 0 && boot.status[0] != 255) { |
| 186 | LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status); |
| 187 | } |
| 188 | |
| 189 | // --- if arguments weren't supplied, look in the bootloader control block |
| 190 | if (*argc <= 1) { |
| 191 | boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination |
| 192 | const char *arg = strtok(boot.recovery, "\n"); |
| 193 | if (arg != NULL && !strcmp(arg, "recovery")) { |
| 194 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 195 | (*argv)[0] = strdup(arg); |
| 196 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 197 | if ((arg = strtok(NULL, "\n")) == NULL) break; |
| 198 | (*argv)[*argc] = strdup(arg); |
| 199 | } |
| 200 | LOGI("Got arguments from boot message\n"); |
| 201 | } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) { |
| 202 | LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // --- if that doesn't work, try the command file |
| 207 | if (*argc <= 1) { |
| 208 | FILE *fp = fopen_root_path(COMMAND_FILE, "r"); |
| 209 | if (fp != NULL) { |
| 210 | char *argv0 = (*argv)[0]; |
| 211 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 212 | (*argv)[0] = argv0; // use the same program name |
| 213 | |
| 214 | char buf[MAX_ARG_LENGTH]; |
| 215 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 216 | if (!fgets(buf, sizeof(buf), fp)) break; |
| 217 | (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline. |
| 218 | } |
| 219 | |
| 220 | check_and_fclose(fp, COMMAND_FILE); |
| 221 | LOGI("Got arguments from %s\n", COMMAND_FILE); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // --> write the arguments we have back into the bootloader control block |
| 226 | // always boot into recovery after this (until finish_recovery() is called) |
| 227 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 228 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 229 | int i; |
| 230 | for (i = 1; i < *argc; ++i) { |
| 231 | strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); |
| 232 | strlcat(boot.recovery, "\n", sizeof(boot.recovery)); |
| 233 | } |
| 234 | set_bootloader_message(&boot); |
| 235 | } |
| 236 | |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 237 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 238 | set_sdcard_update_bootloader_message() { |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 239 | struct bootloader_message boot; |
| 240 | memset(&boot, 0, sizeof(boot)); |
| 241 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 242 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 243 | set_bootloader_message(&boot); |
| 244 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 245 | |
| 246 | // clear the recovery command and prepare to boot a (hopefully working) system, |
| 247 | // copy our log file to cache as well (for the system to read), and |
| 248 | // record any intent we were asked to communicate back to the system. |
| 249 | // this function is idempotent: call it as many times as you like. |
| 250 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 251 | finish_recovery(const char *send_intent) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 252 | // By this point, we're ready to return to the main system... |
| 253 | if (send_intent != NULL) { |
| 254 | FILE *fp = fopen_root_path(INTENT_FILE, "w"); |
Jay Freeman (saurik) | 619ec2f | 2008-11-17 01:56:05 +0000 | [diff] [blame] | 255 | if (fp == NULL) { |
| 256 | LOGE("Can't open %s\n", INTENT_FILE); |
| 257 | } else { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 258 | fputs(send_intent, fp); |
| 259 | check_and_fclose(fp, INTENT_FILE); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // Copy logs to cache so the system can find out what happened. |
| 264 | FILE *log = fopen_root_path(LOG_FILE, "a"); |
Jay Freeman (saurik) | 619ec2f | 2008-11-17 01:56:05 +0000 | [diff] [blame] | 265 | if (log == NULL) { |
| 266 | LOGE("Can't open %s\n", LOG_FILE); |
| 267 | } else { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 268 | FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r"); |
| 269 | if (tmplog == NULL) { |
| 270 | LOGE("Can't open %s\n", TEMPORARY_LOG_FILE); |
| 271 | } else { |
| 272 | static long tmplog_offset = 0; |
| 273 | fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write |
| 274 | char buf[4096]; |
| 275 | while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log); |
| 276 | tmplog_offset = ftell(tmplog); |
| 277 | check_and_fclose(tmplog, TEMPORARY_LOG_FILE); |
| 278 | } |
| 279 | check_and_fclose(log, LOG_FILE); |
| 280 | } |
| 281 | |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 282 | // Reset to mormal system boot so recovery won't cycle indefinitely. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 283 | struct bootloader_message boot; |
| 284 | memset(&boot, 0, sizeof(boot)); |
| 285 | set_bootloader_message(&boot); |
| 286 | |
| 287 | // Remove the command file, so recovery won't repeat indefinitely. |
| 288 | char path[PATH_MAX] = ""; |
| 289 | if (ensure_root_path_mounted(COMMAND_FILE) != 0 || |
| 290 | translate_root_path(COMMAND_FILE, path, sizeof(path)) == NULL || |
| 291 | (unlink(path) && errno != ENOENT)) { |
| 292 | LOGW("Can't unlink %s\n", COMMAND_FILE); |
| 293 | } |
| 294 | |
| 295 | sync(); // For good measure. |
| 296 | } |
| 297 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 298 | static int |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 299 | erase_root(const char *root) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 300 | ui_set_background(BACKGROUND_ICON_INSTALLING); |
| 301 | ui_show_indeterminate_progress(); |
| 302 | ui_print("Formatting %s...\n", root); |
| 303 | return format_root_device(root); |
| 304 | } |
| 305 | |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 306 | static char* |
| 307 | copy_sideloaded_package(const char* original_root_path) { |
| 308 | if (ensure_root_path_mounted(original_root_path) != 0) { |
| 309 | LOGE("Can't mount %s\n", original_root_path); |
| 310 | return NULL; |
| 311 | } |
| 312 | |
| 313 | char original_path[PATH_MAX] = ""; |
| 314 | if (translate_root_path(original_root_path, original_path, |
| 315 | sizeof(original_path)) == NULL) { |
| 316 | LOGE("Bad path %s\n", original_root_path); |
| 317 | return NULL; |
| 318 | } |
| 319 | |
| 320 | if (ensure_root_path_mounted(SIDELOAD_TEMP_DIR) != 0) { |
| 321 | LOGE("Can't mount %s\n", SIDELOAD_TEMP_DIR); |
| 322 | return NULL; |
| 323 | } |
| 324 | |
| 325 | char copy_path[PATH_MAX] = ""; |
| 326 | if (translate_root_path(SIDELOAD_TEMP_DIR, copy_path, |
| 327 | sizeof(copy_path)) == NULL) { |
| 328 | LOGE("Bad path %s\n", SIDELOAD_TEMP_DIR); |
| 329 | return NULL; |
| 330 | } |
| 331 | |
| 332 | if (mkdir(copy_path, 0700) != 0) { |
| 333 | if (errno != EEXIST) { |
| 334 | LOGE("Can't mkdir %s (%s)\n", SIDELOAD_TEMP_DIR, strerror(errno)); |
| 335 | return NULL; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | struct stat st; |
| 340 | if (stat(copy_path, &st) != 0) { |
| 341 | LOGE("failed to stat %s (%s)\n", copy_path, strerror(errno)); |
| 342 | return NULL; |
| 343 | } |
| 344 | if (!S_ISDIR(st.st_mode)) { |
| 345 | LOGE("%s isn't a directory\n", copy_path); |
| 346 | return NULL; |
| 347 | } |
| 348 | if ((st.st_mode & 0777) != 0700) { |
| 349 | LOGE("%s has perms %o\n", copy_path, st.st_mode); |
| 350 | return NULL; |
| 351 | } |
| 352 | if (st.st_uid != 0) { |
| 353 | LOGE("%s owned by %lu; not root\n", copy_path, st.st_uid); |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | strcat(copy_path, "/package.zip"); |
| 358 | |
| 359 | char* buffer = malloc(BUFSIZ); |
| 360 | if (buffer == NULL) { |
| 361 | LOGE("Failed to allocate buffer\n"); |
| 362 | return NULL; |
| 363 | } |
| 364 | |
| 365 | size_t read; |
| 366 | FILE* fin = fopen(original_path, "rb"); |
| 367 | if (fin == NULL) { |
| 368 | LOGE("Failed to open %s (%s)\n", original_path, strerror(errno)); |
| 369 | return NULL; |
| 370 | } |
| 371 | FILE* fout = fopen(copy_path, "wb"); |
| 372 | if (fout == NULL) { |
| 373 | LOGE("Failed to open %s (%s)\n", copy_path, strerror(errno)); |
| 374 | return NULL; |
| 375 | } |
| 376 | |
| 377 | while ((read = fread(buffer, 1, BUFSIZ, fin)) > 0) { |
| 378 | if (fwrite(buffer, 1, read, fout) != read) { |
| 379 | LOGE("Short write of %s (%s)\n", copy_path, strerror(errno)); |
| 380 | return NULL; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | free(buffer); |
| 385 | |
| 386 | if (fclose(fout) != 0) { |
| 387 | LOGE("Failed to close %s (%s)\n", copy_path, strerror(errno)); |
| 388 | return NULL; |
| 389 | } |
| 390 | |
| 391 | if (fclose(fin) != 0) { |
| 392 | LOGE("Failed to close %s (%s)\n", original_path, strerror(errno)); |
| 393 | return NULL; |
| 394 | } |
| 395 | |
| 396 | // "adb push" is happy to overwrite read-only files when it's |
| 397 | // running as root, but we'll try anyway. |
| 398 | if (chmod(copy_path, 0400) != 0) { |
| 399 | LOGE("Failed to chmod %s (%s)\n", copy_path, strerror(errno)); |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | char* copy_root_path = malloc(strlen(SIDELOAD_TEMP_DIR) + 20); |
| 404 | strcpy(copy_root_path, SIDELOAD_TEMP_DIR); |
| 405 | strcat(copy_root_path, "/package.zip"); |
| 406 | return copy_root_path; |
| 407 | } |
| 408 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 409 | static char** |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 410 | prepend_title(const char** headers) { |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 411 | char* title[] = { "Android system recovery <" |
Doug Zongker | 64893cc | 2009-07-14 16:31:56 -0700 | [diff] [blame] | 412 | EXPAND(RECOVERY_API_VERSION) "e>", |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 413 | "", |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 414 | NULL }; |
| 415 | |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 416 | // count the number of lines in our title, plus the |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 417 | // caller-provided headers. |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 418 | int count = 0; |
| 419 | char** p; |
| 420 | for (p = title; *p; ++p, ++count); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 421 | for (p = headers; *p; ++p, ++count); |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 422 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 423 | char** new_headers = malloc((count+1) * sizeof(char*)); |
| 424 | char** h = new_headers; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 425 | for (p = title; *p; ++p, ++h) *h = *p; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 426 | for (p = headers; *p; ++p, ++h) *h = *p; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 427 | *h = NULL; |
| 428 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 429 | return new_headers; |
| 430 | } |
| 431 | |
| 432 | static int |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 433 | get_menu_selection(char** headers, char** items, int menu_only, |
| 434 | int initial_selection) { |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 435 | // throw away keys pressed previously, so user doesn't |
| 436 | // accidentally trigger menu items. |
| 437 | ui_clear_key_queue(); |
| 438 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 439 | ui_start_menu(headers, items, initial_selection); |
| 440 | int selected = initial_selection; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 441 | int chosen_item = -1; |
| 442 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 443 | while (chosen_item < 0) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 444 | int key = ui_wait_key(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 445 | int visible = ui_text_visible(); |
| 446 | |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 447 | int action = device_handle_key(key, visible); |
| 448 | |
| 449 | if (action < 0) { |
| 450 | switch (action) { |
| 451 | case HIGHLIGHT_UP: |
| 452 | --selected; |
| 453 | selected = ui_menu_select(selected); |
| 454 | break; |
| 455 | case HIGHLIGHT_DOWN: |
| 456 | ++selected; |
| 457 | selected = ui_menu_select(selected); |
| 458 | break; |
| 459 | case SELECT_ITEM: |
| 460 | chosen_item = selected; |
| 461 | break; |
| 462 | case NO_ACTION: |
| 463 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 464 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 465 | } else if (!menu_only) { |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 466 | chosen_item = action; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 467 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 468 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 469 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 470 | ui_end_menu(); |
| 471 | return chosen_item; |
| 472 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 473 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 474 | static int compare_string(const void* a, const void* b) { |
| 475 | return strcmp(*(const char**)a, *(const char**)b); |
| 476 | } |
| 477 | |
| 478 | static int |
| 479 | sdcard_directory(const char* root_path) { |
| 480 | const char* MENU_HEADERS[] = { "Choose a package to install:", |
| 481 | root_path, |
| 482 | "", |
| 483 | NULL }; |
| 484 | DIR* d; |
| 485 | struct dirent* de; |
| 486 | char path[PATH_MAX]; |
| 487 | d = opendir(translate_root_path(root_path, path, sizeof(path))); |
| 488 | if (d == NULL) { |
| 489 | LOGE("error opening %s: %s\n", path, strerror(errno)); |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | char** headers = prepend_title(MENU_HEADERS); |
| 494 | |
| 495 | int d_size = 0; |
| 496 | int d_alloc = 10; |
| 497 | char** dirs = malloc(d_alloc * sizeof(char*)); |
| 498 | int z_size = 1; |
| 499 | int z_alloc = 10; |
| 500 | char** zips = malloc(z_alloc * sizeof(char*)); |
| 501 | zips[0] = strdup("../"); |
| 502 | |
| 503 | while ((de = readdir(d)) != NULL) { |
| 504 | int name_len = strlen(de->d_name); |
| 505 | |
| 506 | if (de->d_type == DT_DIR) { |
| 507 | // skip "." and ".." entries |
| 508 | if (name_len == 1 && de->d_name[0] == '.') continue; |
| 509 | if (name_len == 2 && de->d_name[0] == '.' && |
| 510 | de->d_name[1] == '.') continue; |
| 511 | |
| 512 | if (d_size >= d_alloc) { |
| 513 | d_alloc *= 2; |
| 514 | dirs = realloc(dirs, d_alloc * sizeof(char*)); |
| 515 | } |
| 516 | dirs[d_size] = malloc(name_len + 2); |
| 517 | strcpy(dirs[d_size], de->d_name); |
| 518 | dirs[d_size][name_len] = '/'; |
| 519 | dirs[d_size][name_len+1] = '\0'; |
| 520 | ++d_size; |
| 521 | } else if (de->d_type == DT_REG && |
| 522 | name_len >= 4 && |
| 523 | strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) { |
| 524 | if (z_size >= z_alloc) { |
| 525 | z_alloc *= 2; |
| 526 | zips = realloc(zips, z_alloc * sizeof(char*)); |
| 527 | } |
| 528 | zips[z_size++] = strdup(de->d_name); |
| 529 | } |
| 530 | } |
| 531 | closedir(d); |
| 532 | |
| 533 | qsort(dirs, d_size, sizeof(char*), compare_string); |
| 534 | qsort(zips, z_size, sizeof(char*), compare_string); |
| 535 | |
| 536 | // append dirs to the zips list |
| 537 | if (d_size + z_size + 1 > z_alloc) { |
| 538 | z_alloc = d_size + z_size + 1; |
| 539 | zips = realloc(zips, z_alloc * sizeof(char*)); |
| 540 | } |
| 541 | memcpy(zips + z_size, dirs, d_size * sizeof(char*)); |
| 542 | free(dirs); |
| 543 | z_size += d_size; |
| 544 | zips[z_size] = NULL; |
| 545 | |
| 546 | int result; |
| 547 | int chosen_item = 0; |
| 548 | do { |
| 549 | chosen_item = get_menu_selection(headers, zips, 1, chosen_item); |
| 550 | |
| 551 | char* item = zips[chosen_item]; |
| 552 | int item_len = strlen(item); |
| 553 | if (chosen_item == 0) { // item 0 is always "../" |
| 554 | // go up but continue browsing (if the caller is sdcard_directory) |
| 555 | result = -1; |
| 556 | break; |
| 557 | } else if (item[item_len-1] == '/') { |
| 558 | // recurse down into a subdirectory |
| 559 | char new_path[PATH_MAX]; |
| 560 | strlcpy(new_path, root_path, PATH_MAX); |
| 561 | strlcat(new_path, item, PATH_MAX); |
| 562 | result = sdcard_directory(new_path); |
| 563 | if (result >= 0) break; |
| 564 | } else { |
| 565 | // selected a zip file: attempt to install it, and return |
| 566 | // the status to the caller. |
| 567 | char new_path[PATH_MAX]; |
| 568 | strlcpy(new_path, root_path, PATH_MAX); |
| 569 | strlcat(new_path, item, PATH_MAX); |
| 570 | |
| 571 | ui_print("\n-- Install %s ...\n", new_path); |
| 572 | set_sdcard_update_bootloader_message(); |
| 573 | result = install_package(new_path); |
| 574 | break; |
| 575 | } |
| 576 | } while (true); |
| 577 | |
| 578 | int i; |
| 579 | for (i = 0; i < z_size; ++i) free(zips[i]); |
| 580 | free(zips); |
| 581 | free(headers); |
| 582 | |
| 583 | return result; |
| 584 | } |
| 585 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 586 | static void |
| 587 | wipe_data(int confirm) { |
| 588 | if (confirm) { |
| 589 | static char** title_headers = NULL; |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 590 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 591 | if (title_headers == NULL) { |
| 592 | char* headers[] = { "Confirm wipe of all user data?", |
| 593 | " THIS CAN NOT BE UNDONE.", |
| 594 | "", |
| 595 | NULL }; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 596 | title_headers = prepend_title((const char**)headers); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 597 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 598 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 599 | char* items[] = { " No", |
| 600 | " No", |
| 601 | " No", |
| 602 | " No", |
| 603 | " No", |
| 604 | " No", |
| 605 | " No", |
| 606 | " Yes -- delete all user data", // [7] |
| 607 | " No", |
| 608 | " No", |
| 609 | " No", |
| 610 | NULL }; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 611 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 612 | int chosen_item = get_menu_selection(title_headers, items, 1, 0); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 613 | if (chosen_item != 7) { |
| 614 | return; |
| 615 | } |
| 616 | } |
Doug Zongker | 1066d2c | 2009-04-01 13:57:40 -0700 | [diff] [blame] | 617 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 618 | ui_print("\n-- Wiping data...\n"); |
| 619 | device_wipe_data(); |
| 620 | erase_root("DATA:"); |
| 621 | erase_root("CACHE:"); |
| 622 | ui_print("Data wipe complete.\n"); |
| 623 | } |
| 624 | |
| 625 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 626 | prompt_and_wait() { |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 627 | char** headers = prepend_title((const char**)MENU_HEADERS); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 628 | |
| 629 | for (;;) { |
| 630 | finish_recovery(NULL); |
| 631 | ui_reset_progress(); |
| 632 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 633 | int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 634 | |
| 635 | // device-specific code may take some action here. It may |
| 636 | // return one of the core actions handled in the switch |
| 637 | // statement below. |
| 638 | chosen_item = device_perform_action(chosen_item); |
| 639 | |
| 640 | switch (chosen_item) { |
| 641 | case ITEM_REBOOT: |
| 642 | return; |
| 643 | |
| 644 | case ITEM_WIPE_DATA: |
| 645 | wipe_data(ui_text_visible()); |
| 646 | if (!ui_text_visible()) return; |
| 647 | break; |
| 648 | |
| 649 | case ITEM_WIPE_CACHE: |
| 650 | ui_print("\n-- Wiping cache...\n"); |
| 651 | erase_root("CACHE:"); |
| 652 | ui_print("Cache wipe complete.\n"); |
| 653 | if (!ui_text_visible()) return; |
| 654 | break; |
| 655 | |
| 656 | case ITEM_APPLY_SDCARD: |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 657 | ; |
| 658 | int status = sdcard_directory(SDCARD_ROOT); |
| 659 | if (status >= 0) { |
| 660 | if (status != INSTALL_SUCCESS) { |
| 661 | ui_set_background(BACKGROUND_ICON_ERROR); |
| 662 | ui_print("Installation aborted.\n"); |
| 663 | } else if (!ui_text_visible()) { |
| 664 | return; // reboot if logs aren't visible |
| 665 | } else { |
| 666 | ui_print("\nInstall from sdcard complete.\n"); |
| 667 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 668 | } |
| 669 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 675 | print_property(const char *key, const char *name, void *cookie) { |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame^] | 676 | printf("%s=%s\n", key, name); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | int |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 680 | main(int argc, char **argv) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 681 | time_t start = time(NULL); |
| 682 | |
| 683 | // If these fail, there's not really anywhere to complain... |
| 684 | freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); |
| 685 | freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame^] | 686 | printf("Starting recovery on %s", ctime(&start)); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 687 | |
| 688 | ui_init(); |
| 689 | get_args(&argc, &argv); |
| 690 | |
| 691 | int previous_runs = 0; |
| 692 | const char *send_intent = NULL; |
| 693 | const char *update_package = NULL; |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 694 | const char *encrypted_fs_mode = NULL; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 695 | int wipe_data = 0, wipe_cache = 0; |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 696 | int toggle_secure_fs = 0; |
| 697 | encrypted_fs_info encrypted_fs_data; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 698 | |
| 699 | int arg; |
| 700 | while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { |
| 701 | switch (arg) { |
| 702 | case 'p': previous_runs = atoi(optarg); break; |
| 703 | case 's': send_intent = optarg; break; |
| 704 | case 'u': update_package = optarg; break; |
| 705 | case 'w': wipe_data = wipe_cache = 1; break; |
| 706 | case 'c': wipe_cache = 1; break; |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 707 | case 'e': encrypted_fs_mode = optarg; toggle_secure_fs = 1; break; |
Doug Zongker | 4bc9806 | 2010-09-03 11:00:13 -0700 | [diff] [blame] | 708 | case 't': ui_show_text(1); break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 709 | case '?': |
| 710 | LOGE("Invalid command argument\n"); |
| 711 | continue; |
| 712 | } |
| 713 | } |
| 714 | |
Doug Zongker | efa1bab | 2010-02-01 15:59:12 -0800 | [diff] [blame] | 715 | device_recovery_start(); |
| 716 | |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame^] | 717 | printf("Command:"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 718 | for (arg = 0; arg < argc; arg++) { |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame^] | 719 | printf(" \"%s\"", argv[arg]); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 720 | } |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame^] | 721 | printf("\n\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 722 | |
| 723 | property_list(print_property, NULL); |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame^] | 724 | printf("\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 725 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 726 | int status = INSTALL_SUCCESS; |
| 727 | |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 728 | if (toggle_secure_fs) { |
| 729 | if (strcmp(encrypted_fs_mode,"on") == 0) { |
| 730 | encrypted_fs_data.mode = MODE_ENCRYPTED_FS_ENABLED; |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 731 | ui_print("Enabling Encrypted FS.\n"); |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 732 | } else if (strcmp(encrypted_fs_mode,"off") == 0) { |
| 733 | encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED; |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 734 | ui_print("Disabling Encrypted FS.\n"); |
| 735 | } else { |
| 736 | ui_print("Error: invalid Encrypted FS setting.\n"); |
| 737 | status = INSTALL_ERROR; |
| 738 | } |
| 739 | |
| 740 | // Recovery strategy: if the data partition is damaged, disable encrypted file systems. |
| 741 | // This preventsthe device recycling endlessly in recovery mode. |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 742 | if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) && |
| 743 | (read_encrypted_fs_info(&encrypted_fs_data))) { |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 744 | ui_print("Encrypted FS change aborted, resetting to disabled state.\n"); |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 745 | encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED; |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | if (status != INSTALL_ERROR) { |
| 749 | if (erase_root("DATA:")) { |
| 750 | ui_print("Data wipe failed.\n"); |
| 751 | status = INSTALL_ERROR; |
| 752 | } else if (erase_root("CACHE:")) { |
| 753 | ui_print("Cache wipe failed.\n"); |
| 754 | status = INSTALL_ERROR; |
Oscar Montemayor | 52219a6 | 2010-02-25 16:47:02 -0800 | [diff] [blame] | 755 | } else if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) && |
| 756 | (restore_encrypted_fs_info(&encrypted_fs_data))) { |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 757 | ui_print("Encrypted FS change aborted.\n"); |
| 758 | status = INSTALL_ERROR; |
| 759 | } else { |
| 760 | ui_print("Successfully updated Encrypted FS.\n"); |
| 761 | status = INSTALL_SUCCESS; |
| 762 | } |
| 763 | } |
| 764 | } else if (update_package != NULL) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 765 | status = install_package(update_package); |
| 766 | if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 767 | } else if (wipe_data) { |
| 768 | if (device_wipe_data()) status = INSTALL_ERROR; |
| 769 | if (erase_root("DATA:")) status = INSTALL_ERROR; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 770 | if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; |
| 771 | if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 772 | } else if (wipe_cache) { |
| 773 | if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; |
| 774 | if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 775 | } else { |
| 776 | status = INSTALL_ERROR; // No command specified |
| 777 | } |
| 778 | |
| 779 | if (status != INSTALL_SUCCESS) ui_set_background(BACKGROUND_ICON_ERROR); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 780 | if (status != INSTALL_SUCCESS || ui_text_visible()) { |
| 781 | // Mount the sdcard when the menu is enabled so you can "adb |
| 782 | // push" packages to the sdcard and immediately install them. |
| 783 | ensure_root_path_mounted(SDCARD_ROOT); |
| 784 | prompt_and_wait(); |
| 785 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 786 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 787 | // Otherwise, get ready to boot the main system... |
| 788 | finish_recovery(send_intent); |
| 789 | ui_print("Rebooting...\n"); |
| 790 | sync(); |
| 791 | reboot(RB_AUTOBOOT); |
| 792 | return EXIT_SUCCESS; |
| 793 | } |