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