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 |
Shashank Mittal | 815ca5d | 2010-07-27 11:09:19 -0700 | [diff] [blame] | 3 | * Copyright (c) 2010, Code Aurora Forum. All rights reserved. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <ctype.h> |
| 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <getopt.h> |
| 22 | #include <limits.h> |
| 23 | #include <linux/input.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.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> |
Koushik Dutta | 1741dcd | 2010-06-11 00:49:49 -0700 | [diff] [blame] | 32 | #include <sys/stat.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 33 | |
| 34 | #include "bootloader.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 35 | #include "common.h" |
| 36 | #include "cutils/properties.h" |
Ken Sumrall | 6e4472a | 2011-03-07 23:37:27 -0800 | [diff] [blame] | 37 | #include "cutils/android_reboot.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 38 | #include "install.h" |
| 39 | #include "minui/minui.h" |
| 40 | #include "minzip/DirUtil.h" |
| 41 | #include "roots.h" |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 42 | #include "recovery_ui.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 43 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 44 | #include "extendedcommands.h" |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 45 | #include "flashutils/flashutils.h" |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 46 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 47 | static const struct option OPTIONS[] = { |
| 48 | { "send_intent", required_argument, NULL, 's' }, |
| 49 | { "update_package", required_argument, NULL, 'u' }, |
| 50 | { "wipe_data", no_argument, NULL, 'w' }, |
| 51 | { "wipe_cache", no_argument, NULL, 'c' }, |
Doug Zongker | 4bc9806 | 2010-09-03 11:00:13 -0700 | [diff] [blame] | 52 | { "show_text", no_argument, NULL, 't' }, |
Doug Zongker | 988500b | 2009-10-06 14:41:38 -0700 | [diff] [blame] | 53 | { NULL, 0, NULL, 0 }, |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 56 | static const char *COMMAND_FILE = "/cache/recovery/command"; |
| 57 | static const char *INTENT_FILE = "/cache/recovery/intent"; |
| 58 | static const char *LOG_FILE = "/cache/recovery/log"; |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 59 | static const char *LAST_LOG_FILE = "/cache/recovery/last_log"; |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 60 | static const char *CACHE_ROOT = "/cache"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 61 | static const char *SDCARD_ROOT = "/sdcard"; |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 62 | static int allow_display_toggle = 1; |
KalimochoAz | d646a6f | 2011-01-10 06:14:21 +0100 | [diff] [blame] | 63 | static int poweroff = 0; |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 64 | static const char *SDCARD_PACKAGE_FILE = "/sdcard/update.zip"; |
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 | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 66 | static const char *SIDELOAD_TEMP_DIR = "/tmp/sideload"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 67 | |
Doug Zongker | 6809c51 | 2011-03-01 14:04:34 -0800 | [diff] [blame] | 68 | extern UIParameters ui_parameters; // from ui.c |
| 69 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 70 | /* |
| 71 | * The recovery tool communicates with the main system through /cache files. |
| 72 | * /cache/recovery/command - INPUT - command line for tool, one arg per line |
| 73 | * /cache/recovery/log - OUTPUT - combined log file from recovery run(s) |
| 74 | * /cache/recovery/intent - OUTPUT - intent that was passed in |
| 75 | * |
| 76 | * The arguments which may be supplied in the recovery.command file: |
| 77 | * --send_intent=anystring - write the text out to recovery.intent |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 78 | * --update_package=path - verify install an OTA package file |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 79 | * --wipe_data - erase user data (and cache), then reboot |
| 80 | * --wipe_cache - wipe cache (but not user data), then reboot |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 81 | * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 82 | * |
| 83 | * After completing, we remove /cache/recovery/command and reboot. |
| 84 | * Arguments may also be supplied in the bootloader control block (BCB). |
| 85 | * These important scenarios must be safely restartable at any point: |
| 86 | * |
| 87 | * FACTORY RESET |
| 88 | * 1. user selects "factory reset" |
| 89 | * 2. main system writes "--wipe_data" to /cache/recovery/command |
| 90 | * 3. main system reboots into recovery |
| 91 | * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data" |
| 92 | * -- after this, rebooting will restart the erase -- |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 93 | * 5. erase_volume() reformats /data |
| 94 | * 6. erase_volume() reformats /cache |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 95 | * 7. finish_recovery() erases BCB |
| 96 | * -- after this, rebooting will restart the main system -- |
| 97 | * 8. main() calls reboot() to boot main system |
| 98 | * |
| 99 | * OTA INSTALL |
| 100 | * 1. main system downloads OTA package to /cache/some-filename.zip |
Doug Zongker | 9b125b0 | 2010-09-22 12:01:37 -0700 | [diff] [blame] | 101 | * 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] | 102 | * 3. main system reboots into recovery |
| 103 | * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..." |
| 104 | * -- after this, rebooting will attempt to reinstall the update -- |
| 105 | * 5. install_package() attempts to install the update |
| 106 | * NOTE: the package install must itself be restartable from any point |
| 107 | * 6. finish_recovery() erases BCB |
| 108 | * -- after this, rebooting will (try to) restart the main system -- |
| 109 | * 7. ** if install failed ** |
| 110 | * 7a. prompt_and_wait() shows an error icon and waits for the user |
| 111 | * 7b; the user reboots (pulling the battery, etc) into the main system |
| 112 | * 8. main() calls maybe_install_firmware_update() |
| 113 | * ** if the update contained radio/hboot firmware **: |
| 114 | * 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache" |
| 115 | * -- after this, rebooting will reformat cache & restart main system -- |
| 116 | * 8b. m_i_f_u() writes firmware image into raw cache partition |
| 117 | * 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache" |
| 118 | * -- after this, rebooting will attempt to reinstall firmware -- |
| 119 | * 8d. bootloader tries to flash firmware |
| 120 | * 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache") |
| 121 | * -- after this, rebooting will reformat cache & restart main system -- |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 122 | * 8f. erase_volume() reformats /cache |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 123 | * 8g. finish_recovery() erases BCB |
| 124 | * -- after this, rebooting will (try to) restart the main system -- |
| 125 | * 9. main() calls reboot() to boot main system |
| 126 | */ |
| 127 | |
| 128 | static const int MAX_ARG_LENGTH = 4096; |
| 129 | static const int MAX_ARGS = 100; |
| 130 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 131 | // open a given path, mounting partitions as necessary |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 132 | FILE* |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 133 | fopen_path(const char *path, const char *mode) { |
| 134 | if (ensure_path_mounted(path) != 0) { |
| 135 | LOGE("Can't mount %s\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 136 | return NULL; |
| 137 | } |
| 138 | |
| 139 | // When writing, try to create the containing directory, if necessary. |
| 140 | // Use generous permissions, the system (init.rc) will reset them. |
| 141 | if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1); |
| 142 | |
| 143 | FILE *fp = fopen(path, mode); |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 144 | if (fp == NULL && path != COMMAND_FILE) LOGE("Can't open %s\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 145 | return fp; |
| 146 | } |
| 147 | |
| 148 | // close a file, log an error if the error indicator is set |
| 149 | static void |
| 150 | check_and_fclose(FILE *fp, const char *name) { |
| 151 | fflush(fp); |
| 152 | if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno)); |
| 153 | fclose(fp); |
| 154 | } |
| 155 | |
| 156 | // command line args come from, in decreasing precedence: |
| 157 | // - the actual command line |
| 158 | // - the bootloader control block (one per line, after "recovery") |
| 159 | // - the contents of COMMAND_FILE (one per line) |
| 160 | static void |
| 161 | get_args(int *argc, char ***argv) { |
| 162 | struct bootloader_message boot; |
| 163 | memset(&boot, 0, sizeof(boot)); |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 164 | if (device_flash_type() == MTD) { |
| 165 | get_bootloader_message(&boot); // this may fail, leaving a zeroed structure |
| 166 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 167 | |
| 168 | if (boot.command[0] != 0 && boot.command[0] != 255) { |
| 169 | LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command); |
| 170 | } |
| 171 | |
| 172 | if (boot.status[0] != 0 && boot.status[0] != 255) { |
| 173 | LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status); |
| 174 | } |
| 175 | |
Koushik Dutta | 1741dcd | 2010-06-11 00:49:49 -0700 | [diff] [blame] | 176 | struct stat file_info; |
| 177 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 178 | // --- if arguments weren't supplied, look in the bootloader control block |
Koushik Dutta | 1741dcd | 2010-06-11 00:49:49 -0700 | [diff] [blame] | 179 | if (*argc <= 1 && 0 != stat("/tmp/.ignorebootmessage", &file_info)) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 180 | boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination |
| 181 | const char *arg = strtok(boot.recovery, "\n"); |
| 182 | if (arg != NULL && !strcmp(arg, "recovery")) { |
| 183 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 184 | (*argv)[0] = strdup(arg); |
| 185 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 186 | if ((arg = strtok(NULL, "\n")) == NULL) break; |
| 187 | (*argv)[*argc] = strdup(arg); |
| 188 | } |
| 189 | LOGI("Got arguments from boot message\n"); |
| 190 | } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) { |
| 191 | LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // --- if that doesn't work, try the command file |
| 196 | if (*argc <= 1) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 197 | FILE *fp = fopen_path(COMMAND_FILE, "r"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 198 | if (fp != NULL) { |
| 199 | char *argv0 = (*argv)[0]; |
| 200 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 201 | (*argv)[0] = argv0; // use the same program name |
| 202 | |
| 203 | char buf[MAX_ARG_LENGTH]; |
| 204 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 205 | if (!fgets(buf, sizeof(buf), fp)) break; |
| 206 | (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline. |
| 207 | } |
| 208 | |
| 209 | check_and_fclose(fp, COMMAND_FILE); |
| 210 | LOGI("Got arguments from %s\n", COMMAND_FILE); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // --> write the arguments we have back into the bootloader control block |
| 215 | // always boot into recovery after this (until finish_recovery() is called) |
| 216 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 217 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 218 | int i; |
| 219 | for (i = 1; i < *argc; ++i) { |
| 220 | strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); |
| 221 | strlcat(boot.recovery, "\n", sizeof(boot.recovery)); |
| 222 | } |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 223 | if (device_flash_type() == MTD) { |
| 224 | set_bootloader_message(&boot); |
| 225 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 228 | void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 229 | set_sdcard_update_bootloader_message() { |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 230 | struct bootloader_message boot; |
| 231 | memset(&boot, 0, sizeof(boot)); |
| 232 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 233 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 234 | set_bootloader_message(&boot); |
| 235 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 236 | |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 237 | // How much of the temp log we have copied to the copy in cache. |
| 238 | static long tmplog_offset = 0; |
| 239 | |
| 240 | static void |
| 241 | copy_log_file(const char* destination, int append) { |
| 242 | FILE *log = fopen_path(destination, append ? "a" : "w"); |
| 243 | if (log == NULL) { |
| 244 | LOGE("Can't open %s\n", destination); |
| 245 | } else { |
| 246 | FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r"); |
| 247 | if (tmplog == NULL) { |
| 248 | LOGE("Can't open %s\n", TEMPORARY_LOG_FILE); |
| 249 | } else { |
| 250 | if (append) { |
| 251 | fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write |
| 252 | } |
| 253 | char buf[4096]; |
| 254 | while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log); |
| 255 | if (append) { |
| 256 | tmplog_offset = ftell(tmplog); |
| 257 | } |
| 258 | check_and_fclose(tmplog, TEMPORARY_LOG_FILE); |
| 259 | } |
| 260 | check_and_fclose(log, destination); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 265 | // clear the recovery command and prepare to boot a (hopefully working) system, |
| 266 | // copy our log file to cache as well (for the system to read), and |
| 267 | // record any intent we were asked to communicate back to the system. |
| 268 | // this function is idempotent: call it as many times as you like. |
| 269 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 270 | finish_recovery(const char *send_intent) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 271 | // By this point, we're ready to return to the main system... |
| 272 | if (send_intent != NULL) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 273 | FILE *fp = fopen_path(INTENT_FILE, "w"); |
Jay Freeman (saurik) | 619ec2f | 2008-11-17 01:56:05 +0000 | [diff] [blame] | 274 | if (fp == NULL) { |
| 275 | LOGE("Can't open %s\n", INTENT_FILE); |
| 276 | } else { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 277 | fputs(send_intent, fp); |
| 278 | check_and_fclose(fp, INTENT_FILE); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // Copy logs to cache so the system can find out what happened. |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 283 | copy_log_file(LOG_FILE, true); |
| 284 | copy_log_file(LAST_LOG_FILE, false); |
| 285 | chmod(LAST_LOG_FILE, 0640); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 286 | |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 287 | if (device_flash_type() == MTD) { |
| 288 | // Reset to mormal system boot so recovery won't cycle indefinitely. |
| 289 | struct bootloader_message boot; |
| 290 | memset(&boot, 0, sizeof(boot)); |
| 291 | set_bootloader_message(&boot); |
| 292 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 293 | |
| 294 | // Remove the command file, so recovery won't repeat indefinitely. |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 295 | if (ensure_path_mounted(COMMAND_FILE) != 0 || |
| 296 | (unlink(COMMAND_FILE) && errno != ENOENT)) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 297 | LOGW("Can't unlink %s\n", COMMAND_FILE); |
| 298 | } |
| 299 | |
| 300 | sync(); // For good measure. |
| 301 | } |
| 302 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 303 | static int |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 304 | erase_volume(const char *volume) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 305 | ui_set_background(BACKGROUND_ICON_INSTALLING); |
| 306 | ui_show_indeterminate_progress(); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 307 | ui_print("Formatting %s...\n", volume); |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 308 | |
| 309 | if (strcmp(volume, "/cache") == 0) { |
| 310 | // Any part of the log we'd copied to cache is now gone. |
| 311 | // Reset the pointer so we copy from the beginning of the temp |
| 312 | // log. |
| 313 | tmplog_offset = 0; |
| 314 | } |
| 315 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 316 | return format_volume(volume); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 319 | static char* |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 320 | copy_sideloaded_package(const char* original_path) { |
| 321 | if (ensure_path_mounted(original_path) != 0) { |
| 322 | LOGE("Can't mount %s\n", original_path); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 323 | return NULL; |
| 324 | } |
| 325 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 326 | if (ensure_path_mounted(SIDELOAD_TEMP_DIR) != 0) { |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 327 | LOGE("Can't mount %s\n", SIDELOAD_TEMP_DIR); |
| 328 | return NULL; |
| 329 | } |
| 330 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 331 | if (mkdir(SIDELOAD_TEMP_DIR, 0700) != 0) { |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 332 | if (errno != EEXIST) { |
| 333 | LOGE("Can't mkdir %s (%s)\n", SIDELOAD_TEMP_DIR, strerror(errno)); |
| 334 | return NULL; |
| 335 | } |
| 336 | } |
| 337 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 338 | // verify that SIDELOAD_TEMP_DIR is exactly what we expect: a |
| 339 | // directory, owned by root, readable and writable only by root. |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 340 | struct stat st; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 341 | if (stat(SIDELOAD_TEMP_DIR, &st) != 0) { |
| 342 | LOGE("failed to stat %s (%s)\n", SIDELOAD_TEMP_DIR, strerror(errno)); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 343 | return NULL; |
| 344 | } |
| 345 | if (!S_ISDIR(st.st_mode)) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 346 | LOGE("%s isn't a directory\n", SIDELOAD_TEMP_DIR); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
| 349 | if ((st.st_mode & 0777) != 0700) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 350 | LOGE("%s has perms %o\n", SIDELOAD_TEMP_DIR, st.st_mode); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 351 | return NULL; |
| 352 | } |
| 353 | if (st.st_uid != 0) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 354 | 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] | 355 | return NULL; |
| 356 | } |
| 357 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 358 | char copy_path[PATH_MAX]; |
| 359 | strcpy(copy_path, SIDELOAD_TEMP_DIR); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 360 | strcat(copy_path, "/package.zip"); |
| 361 | |
| 362 | char* buffer = malloc(BUFSIZ); |
| 363 | if (buffer == NULL) { |
| 364 | LOGE("Failed to allocate buffer\n"); |
| 365 | return NULL; |
| 366 | } |
| 367 | |
| 368 | size_t read; |
| 369 | FILE* fin = fopen(original_path, "rb"); |
| 370 | if (fin == NULL) { |
| 371 | LOGE("Failed to open %s (%s)\n", original_path, strerror(errno)); |
| 372 | return NULL; |
| 373 | } |
| 374 | FILE* fout = fopen(copy_path, "wb"); |
| 375 | if (fout == NULL) { |
| 376 | LOGE("Failed to open %s (%s)\n", copy_path, strerror(errno)); |
| 377 | return NULL; |
| 378 | } |
| 379 | |
| 380 | while ((read = fread(buffer, 1, BUFSIZ, fin)) > 0) { |
| 381 | if (fwrite(buffer, 1, read, fout) != read) { |
| 382 | LOGE("Short write of %s (%s)\n", copy_path, strerror(errno)); |
| 383 | return NULL; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | free(buffer); |
| 388 | |
| 389 | if (fclose(fout) != 0) { |
| 390 | LOGE("Failed to close %s (%s)\n", copy_path, strerror(errno)); |
| 391 | return NULL; |
| 392 | } |
| 393 | |
| 394 | if (fclose(fin) != 0) { |
| 395 | LOGE("Failed to close %s (%s)\n", original_path, strerror(errno)); |
| 396 | return NULL; |
| 397 | } |
| 398 | |
| 399 | // "adb push" is happy to overwrite read-only files when it's |
| 400 | // running as root, but we'll try anyway. |
| 401 | if (chmod(copy_path, 0400) != 0) { |
| 402 | LOGE("Failed to chmod %s (%s)\n", copy_path, strerror(errno)); |
| 403 | return NULL; |
| 404 | } |
| 405 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 406 | return strdup(copy_path); |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 409 | static char** |
| 410 | prepend_title(char** headers) { |
Koushik K. Dutta | 581bd86 | 2010-03-20 01:08:55 -0700 | [diff] [blame] | 411 | char* title[] = { EXPAND(RECOVERY_VERSION), |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 412 | "", |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 413 | NULL }; |
| 414 | |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 415 | // count the number of lines in our title, plus the |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 416 | // caller-provided headers. |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 417 | int count = 0; |
| 418 | char** p; |
| 419 | for (p = title; *p; ++p, ++count); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 420 | for (p = headers; *p; ++p, ++count); |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 421 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 422 | char** new_headers = malloc((count+1) * sizeof(char*)); |
| 423 | char** h = new_headers; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 424 | for (p = title; *p; ++p, ++h) *h = *p; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 425 | for (p = headers; *p; ++p, ++h) *h = *p; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 426 | *h = NULL; |
| 427 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 428 | return new_headers; |
| 429 | } |
| 430 | |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 431 | int |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 432 | get_menu_selection(char** headers, char** items, int menu_only, |
| 433 | int initial_selection) { |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 434 | // throw away keys pressed previously, so user doesn't |
| 435 | // accidentally trigger menu items. |
| 436 | ui_clear_key_queue(); |
| 437 | |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 438 | int item_count = ui_start_menu(headers, items, initial_selection); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 439 | int selected = initial_selection; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 440 | int chosen_item = -1; |
| 441 | |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 442 | // Some users with dead enter keys need a way to turn on power to select. |
| 443 | // Jiggering across the wrapping menu is one "secret" way to enable it. |
| 444 | // We can't rely on /cache or /sdcard since they may not be available. |
| 445 | int wrap_count = 0; |
| 446 | |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 447 | while (chosen_item < 0 && chosen_item != GO_BACK) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 448 | int key = ui_wait_key(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 449 | int visible = ui_text_visible(); |
| 450 | |
Doug Zongker | 5cae445 | 2011-01-25 13:15:30 -0800 | [diff] [blame] | 451 | if (key == -1) { // ui_wait_key() timed out |
| 452 | if (ui_text_ever_visible()) { |
| 453 | continue; |
| 454 | } else { |
| 455 | LOGI("timed out waiting for key input; rebooting.\n"); |
| 456 | ui_end_menu(); |
| 457 | return ITEM_REBOOT; |
| 458 | } |
| 459 | } |
| 460 | |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 461 | int action = device_handle_key(key, visible); |
| 462 | |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 463 | int old_selected = selected; |
| 464 | |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 465 | if (action < 0) { |
| 466 | switch (action) { |
| 467 | case HIGHLIGHT_UP: |
| 468 | --selected; |
| 469 | selected = ui_menu_select(selected); |
| 470 | break; |
| 471 | case HIGHLIGHT_DOWN: |
| 472 | ++selected; |
| 473 | selected = ui_menu_select(selected); |
| 474 | break; |
| 475 | case SELECT_ITEM: |
| 476 | chosen_item = selected; |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 477 | if (ui_get_showing_back_button()) { |
| 478 | if (chosen_item == item_count) { |
| 479 | chosen_item = GO_BACK; |
| 480 | } |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 481 | } |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 482 | break; |
| 483 | case NO_ACTION: |
| 484 | break; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 485 | case GO_BACK: |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 486 | chosen_item = GO_BACK; |
| 487 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 488 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 489 | } else if (!menu_only) { |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 490 | chosen_item = action; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 491 | } |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 492 | |
| 493 | if (abs(selected - old_selected) > 1) { |
| 494 | wrap_count++; |
| 495 | if (wrap_count == 3) { |
| 496 | wrap_count = 0; |
| 497 | if (ui_get_showing_back_button()) { |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 498 | ui_print("Back menu button disabled.\n"); |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 499 | ui_set_showing_back_button(0); |
| 500 | } |
| 501 | else { |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 502 | ui_print("Back menu button enabled.\n"); |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 503 | ui_set_showing_back_button(1); |
| 504 | } |
| 505 | } |
| 506 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 507 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 508 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 509 | ui_end_menu(); |
Koushik K. Dutta | 981b0cd | 2010-02-22 08:53:34 -0800 | [diff] [blame] | 510 | ui_clear_key_queue(); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 511 | return chosen_item; |
| 512 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 513 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 514 | static int compare_string(const void* a, const void* b) { |
| 515 | return strcmp(*(const char**)a, *(const char**)b); |
| 516 | } |
| 517 | |
| 518 | static int |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 519 | update_directory(const char* path, const char* unmount_when_done) { |
| 520 | ensure_path_mounted(path); |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 521 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 522 | const char* MENU_HEADERS[] = { "Choose a package to install:", |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 523 | path, |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 524 | "", |
| 525 | NULL }; |
| 526 | DIR* d; |
| 527 | struct dirent* de; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 528 | d = opendir(path); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 529 | if (d == NULL) { |
| 530 | LOGE("error opening %s: %s\n", path, strerror(errno)); |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 531 | if (unmount_when_done != NULL) { |
| 532 | ensure_path_unmounted(unmount_when_done); |
| 533 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | char** headers = prepend_title(MENU_HEADERS); |
| 538 | |
| 539 | int d_size = 0; |
| 540 | int d_alloc = 10; |
| 541 | char** dirs = malloc(d_alloc * sizeof(char*)); |
| 542 | int z_size = 1; |
| 543 | int z_alloc = 10; |
| 544 | char** zips = malloc(z_alloc * sizeof(char*)); |
| 545 | zips[0] = strdup("../"); |
| 546 | |
| 547 | while ((de = readdir(d)) != NULL) { |
| 548 | int name_len = strlen(de->d_name); |
| 549 | |
| 550 | if (de->d_type == DT_DIR) { |
| 551 | // skip "." and ".." entries |
| 552 | if (name_len == 1 && de->d_name[0] == '.') continue; |
| 553 | if (name_len == 2 && de->d_name[0] == '.' && |
| 554 | de->d_name[1] == '.') continue; |
| 555 | |
| 556 | if (d_size >= d_alloc) { |
| 557 | d_alloc *= 2; |
| 558 | dirs = realloc(dirs, d_alloc * sizeof(char*)); |
| 559 | } |
| 560 | dirs[d_size] = malloc(name_len + 2); |
| 561 | strcpy(dirs[d_size], de->d_name); |
| 562 | dirs[d_size][name_len] = '/'; |
| 563 | dirs[d_size][name_len+1] = '\0'; |
| 564 | ++d_size; |
| 565 | } else if (de->d_type == DT_REG && |
| 566 | name_len >= 4 && |
| 567 | strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) { |
| 568 | if (z_size >= z_alloc) { |
| 569 | z_alloc *= 2; |
| 570 | zips = realloc(zips, z_alloc * sizeof(char*)); |
| 571 | } |
| 572 | zips[z_size++] = strdup(de->d_name); |
| 573 | } |
| 574 | } |
| 575 | closedir(d); |
| 576 | |
| 577 | qsort(dirs, d_size, sizeof(char*), compare_string); |
| 578 | qsort(zips, z_size, sizeof(char*), compare_string); |
| 579 | |
| 580 | // append dirs to the zips list |
| 581 | if (d_size + z_size + 1 > z_alloc) { |
| 582 | z_alloc = d_size + z_size + 1; |
| 583 | zips = realloc(zips, z_alloc * sizeof(char*)); |
| 584 | } |
| 585 | memcpy(zips + z_size, dirs, d_size * sizeof(char*)); |
| 586 | free(dirs); |
| 587 | z_size += d_size; |
| 588 | zips[z_size] = NULL; |
| 589 | |
| 590 | int result; |
| 591 | int chosen_item = 0; |
| 592 | do { |
| 593 | chosen_item = get_menu_selection(headers, zips, 1, chosen_item); |
| 594 | |
| 595 | char* item = zips[chosen_item]; |
| 596 | int item_len = strlen(item); |
| 597 | if (chosen_item == 0) { // item 0 is always "../" |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 598 | // go up but continue browsing (if the caller is update_directory) |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 599 | result = -1; |
| 600 | break; |
| 601 | } else if (item[item_len-1] == '/') { |
| 602 | // recurse down into a subdirectory |
| 603 | char new_path[PATH_MAX]; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 604 | strlcpy(new_path, path, PATH_MAX); |
| 605 | strlcat(new_path, "/", PATH_MAX); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 606 | strlcat(new_path, item, PATH_MAX); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 607 | new_path[strlen(new_path)-1] = '\0'; // truncate the trailing '/' |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 608 | result = update_directory(new_path, unmount_when_done); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 609 | if (result >= 0) break; |
| 610 | } else { |
| 611 | // selected a zip file: attempt to install it, and return |
| 612 | // the status to the caller. |
| 613 | char new_path[PATH_MAX]; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 614 | strlcpy(new_path, path, PATH_MAX); |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 615 | strlcat(new_path, "/", PATH_MAX); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 616 | strlcat(new_path, item, PATH_MAX); |
| 617 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 618 | ui_print("\n-- Install %s ...\n", path); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 619 | set_sdcard_update_bootloader_message(); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 620 | char* copy = copy_sideloaded_package(new_path); |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 621 | if (unmount_when_done != NULL) { |
| 622 | ensure_path_unmounted(unmount_when_done); |
| 623 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 624 | if (copy) { |
| 625 | result = install_package(copy); |
| 626 | free(copy); |
| 627 | } else { |
| 628 | result = INSTALL_ERROR; |
| 629 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 630 | break; |
| 631 | } |
| 632 | } while (true); |
| 633 | |
| 634 | int i; |
| 635 | for (i = 0; i < z_size; ++i) free(zips[i]); |
| 636 | free(zips); |
| 637 | free(headers); |
| 638 | |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 639 | if (unmount_when_done != NULL) { |
| 640 | ensure_path_unmounted(unmount_when_done); |
| 641 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 642 | return result; |
| 643 | } |
| 644 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 645 | static void |
| 646 | wipe_data(int confirm) { |
| 647 | if (confirm) { |
| 648 | static char** title_headers = NULL; |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 649 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 650 | if (title_headers == NULL) { |
| 651 | char* headers[] = { "Confirm wipe of all user data?", |
| 652 | " THIS CAN NOT BE UNDONE.", |
| 653 | "", |
| 654 | NULL }; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 655 | title_headers = prepend_title((const char**)headers); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 656 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 657 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 658 | char* items[] = { " No", |
| 659 | " No", |
| 660 | " No", |
| 661 | " No", |
| 662 | " No", |
| 663 | " No", |
| 664 | " No", |
| 665 | " Yes -- delete all user data", // [7] |
| 666 | " No", |
| 667 | " No", |
| 668 | " No", |
| 669 | NULL }; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 670 | |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 671 | int chosen_item = get_menu_selection(title_headers, items, 1, 0); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 672 | if (chosen_item != 7) { |
| 673 | return; |
| 674 | } |
| 675 | } |
Doug Zongker | 1066d2c | 2009-04-01 13:57:40 -0700 | [diff] [blame] | 676 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 677 | ui_print("\n-- Wiping data...\n"); |
| 678 | device_wipe_data(); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 679 | erase_volume("/data"); |
| 680 | erase_volume("/cache"); |
Koushik Dutta | 5460f0c | 2010-12-18 22:37:49 -0800 | [diff] [blame] | 681 | if (has_datadata()) { |
| 682 | erase_volume("/datadata"); |
| 683 | } |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 684 | erase_volume("/sd-ext"); |
| 685 | erase_volume("/sdcard/.android_secure"); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 686 | ui_print("Data wipe complete.\n"); |
| 687 | } |
| 688 | |
| 689 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 690 | prompt_and_wait() { |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 691 | char** headers = prepend_title((const char**)MENU_HEADERS); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 692 | |
| 693 | for (;;) { |
| 694 | finish_recovery(NULL); |
| 695 | ui_reset_progress(); |
| 696 | |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 697 | allow_display_toggle = 1; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 698 | int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 699 | allow_display_toggle = 0; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 700 | |
| 701 | // device-specific code may take some action here. It may |
| 702 | // return one of the core actions handled in the switch |
| 703 | // statement below. |
| 704 | chosen_item = device_perform_action(chosen_item); |
| 705 | |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 706 | int status; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 707 | switch (chosen_item) { |
| 708 | case ITEM_REBOOT: |
KalimochoAz | d646a6f | 2011-01-10 06:14:21 +0100 | [diff] [blame] | 709 | poweroff=0; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 710 | return; |
| 711 | |
| 712 | case ITEM_WIPE_DATA: |
| 713 | wipe_data(ui_text_visible()); |
| 714 | if (!ui_text_visible()) return; |
| 715 | break; |
| 716 | |
| 717 | case ITEM_WIPE_CACHE: |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 718 | if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache")) |
| 719 | { |
| 720 | ui_print("\n-- Wiping cache...\n"); |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 721 | erase_volume("/cache"); |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 722 | ui_print("Cache wipe complete.\n"); |
| 723 | if (!ui_text_visible()) return; |
| 724 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case ITEM_APPLY_SDCARD: |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 728 | show_install_update_menu(); |
| 729 | break; |
Michael Ward | 9d2629c | 2011-06-23 22:14:24 -0700 | [diff] [blame] | 730 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 731 | case ITEM_NANDROID: |
| 732 | show_nandroid_menu(); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 733 | break; |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame^] | 734 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 735 | case ITEM_PARTITION: |
| 736 | show_partition_menu(); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 737 | break; |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame^] | 738 | |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 739 | case ITEM_ADVANCED: |
| 740 | show_advanced_menu(); |
Koushik K. Dutta | 1fa52ec | 2010-02-21 21:29:10 -0800 | [diff] [blame] | 741 | break; |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame^] | 742 | |
KalimochoAz | d646a6f | 2011-01-10 06:14:21 +0100 | [diff] [blame] | 743 | case ITEM_POWEROFF: |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame^] | 744 | poweroff = 1; |
KalimochoAz | d646a6f | 2011-01-10 06:14:21 +0100 | [diff] [blame] | 745 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 751 | print_property(const char *key, const char *name, void *cookie) { |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 752 | printf("%s=%s\n", key, name); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | int |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 756 | main(int argc, char **argv) { |
Koushik Dutta | 4fcd523 | 2011-10-28 11:47:02 -0700 | [diff] [blame] | 757 | if (strcmp(basename(argv[0]), "recovery") != 0) |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 758 | { |
| 759 | if (strstr(argv[0], "flash_image") != NULL) |
| 760 | return flash_image_main(argc, argv); |
Koushik Dutta | d8e21c3 | 2011-01-04 10:46:23 -0800 | [diff] [blame] | 761 | if (strstr(argv[0], "volume") != NULL) |
| 762 | return volume_main(argc, argv); |
Koushik Dutta | bec0995 | 2010-12-19 20:37:57 -0800 | [diff] [blame] | 763 | if (strstr(argv[0], "edify") != NULL) |
| 764 | return edify_main(argc, argv); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 765 | if (strstr(argv[0], "dump_image") != NULL) |
| 766 | return dump_image_main(argc, argv); |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 767 | if (strstr(argv[0], "erase_image") != NULL) |
| 768 | return erase_image_main(argc, argv); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 769 | if (strstr(argv[0], "mkyaffs2image") != NULL) |
| 770 | return mkyaffs2image_main(argc, argv); |
| 771 | if (strstr(argv[0], "unyaffs") != NULL) |
| 772 | return unyaffs_main(argc, argv); |
Koushik Dutta | d3cc60b | 2010-07-03 13:56:45 -0700 | [diff] [blame] | 773 | if (strstr(argv[0], "nandroid")) |
| 774 | return nandroid_main(argc, argv); |
Koushik Dutta | 852bb42 | 2010-07-24 11:18:00 -0700 | [diff] [blame] | 775 | if (strstr(argv[0], "reboot")) |
| 776 | return reboot_main(argc, argv); |
Kolja Dummann | 6afbcdc | 2011-07-24 21:40:16 +0200 | [diff] [blame] | 777 | #ifdef BOARD_RECOVERY_HANDLES_MOUNT |
| 778 | if (strstr(argv[0], "mount") && argc == 2 && !strstr(argv[0], "umount")) |
| 779 | { |
| 780 | load_volume_table(); |
| 781 | return ensure_path_mounted(argv[1]); |
| 782 | } |
| 783 | #endif |
KalimochoAz | d646a6f | 2011-01-10 06:14:21 +0100 | [diff] [blame] | 784 | if (strstr(argv[0], "poweroff")){ |
| 785 | return reboot_main(argc, argv); |
| 786 | } |
Koushik Dutta | 852bb42 | 2010-07-24 11:18:00 -0700 | [diff] [blame] | 787 | if (strstr(argv[0], "setprop")) |
| 788 | return setprop_main(argc, argv); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 789 | return busybox_driver(argc, argv); |
| 790 | } |
Koushik Dutta | f8b21c2 | 2010-06-14 12:49:47 -0700 | [diff] [blame] | 791 | __system("/sbin/postrecoveryboot.sh"); |
Koushik Dutta | 4d8c033 | 2011-06-09 14:19:04 -0700 | [diff] [blame] | 792 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 793 | int is_user_initiated_recovery = 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 794 | time_t start = time(NULL); |
| 795 | |
| 796 | // If these fail, there's not really anywhere to complain... |
| 797 | freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); |
| 798 | freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 799 | printf("Starting recovery on %s", ctime(&start)); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 800 | |
Doug Zongker | 6809c51 | 2011-03-01 14:04:34 -0800 | [diff] [blame] | 801 | device_ui_init(&ui_parameters); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 802 | ui_init(); |
Koushik Dutta | fdda0d6 | 2010-07-01 12:52:34 -0700 | [diff] [blame] | 803 | ui_print(EXPAND(RECOVERY_VERSION)"\n"); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 804 | load_volume_table(); |
Koushik Dutta | 4196e0f | 2010-12-19 03:38:29 -0800 | [diff] [blame] | 805 | process_volumes(); |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 806 | LOGI("Processing arguments.\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 807 | get_args(&argc, &argv); |
| 808 | |
| 809 | int previous_runs = 0; |
| 810 | const char *send_intent = NULL; |
| 811 | const char *update_package = NULL; |
| 812 | int wipe_data = 0, wipe_cache = 0; |
| 813 | |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 814 | LOGI("Checking arguments.\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 815 | int arg; |
| 816 | while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { |
| 817 | switch (arg) { |
| 818 | case 'p': previous_runs = atoi(optarg); break; |
| 819 | case 's': send_intent = optarg; break; |
| 820 | case 'u': update_package = optarg; break; |
Koushik Dutta | 94a4bab | 2011-07-13 10:34:23 -0700 | [diff] [blame] | 821 | case 'w': |
Ricardo Cerqueira | 0b06fc0 | 2011-07-07 01:09:52 +0100 | [diff] [blame] | 822 | #ifndef BOARD_RECOVERY_ALWAYS_WIPES |
| 823 | wipe_data = wipe_cache = 1; |
| 824 | #endif |
| 825 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 826 | case 'c': wipe_cache = 1; break; |
Doug Zongker | 4bc9806 | 2010-09-03 11:00:13 -0700 | [diff] [blame] | 827 | case 't': ui_show_text(1); break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 828 | case '?': |
| 829 | LOGE("Invalid command argument\n"); |
| 830 | continue; |
| 831 | } |
| 832 | } |
| 833 | |
Koushik Dutta | 9765a03 | 2010-12-18 21:31:02 -0800 | [diff] [blame] | 834 | LOGI("device_recovery_start()\n"); |
Doug Zongker | efa1bab | 2010-02-01 15:59:12 -0800 | [diff] [blame] | 835 | device_recovery_start(); |
| 836 | |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 837 | printf("Command:"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 838 | for (arg = 0; arg < argc; arg++) { |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 839 | printf(" \"%s\"", argv[arg]); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 840 | } |
Doug Zongker | 9b125b0 | 2010-09-22 12:01:37 -0700 | [diff] [blame] | 841 | printf("\n"); |
| 842 | |
| 843 | if (update_package) { |
| 844 | // For backwards compatibility on the cache partition only, if |
| 845 | // we're given an old 'root' path "CACHE:foo", change it to |
| 846 | // "/cache/foo". |
| 847 | if (strncmp(update_package, "CACHE:", 6) == 0) { |
| 848 | int len = strlen(update_package) + 10; |
| 849 | char* modified_path = malloc(len); |
| 850 | strlcpy(modified_path, "/cache/", len); |
| 851 | strlcat(modified_path, update_package+6, len); |
| 852 | printf("(replacing path \"%s\" with \"%s\")\n", |
| 853 | update_package, modified_path); |
| 854 | update_package = modified_path; |
| 855 | } |
| 856 | } |
| 857 | printf("\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 858 | |
| 859 | property_list(print_property, NULL); |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 860 | printf("\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 861 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 862 | int status = INSTALL_SUCCESS; |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 863 | |
Doug Zongker | 540d57f | 2011-01-18 13:36:58 -0800 | [diff] [blame] | 864 | if (update_package != NULL) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 865 | status = install_package(update_package); |
| 866 | if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 867 | } else if (wipe_data) { |
| 868 | if (device_wipe_data()) status = INSTALL_ERROR; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 869 | if (erase_volume("/data")) status = INSTALL_ERROR; |
| 870 | if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 871 | if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 872 | } else if (wipe_cache) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 873 | if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 874 | 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] | 875 | } else { |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 876 | LOGI("Checking for extendedcommand...\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 877 | status = INSTALL_ERROR; // No command specified |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 878 | // we are starting up in user initiated recovery here |
| 879 | // let's set up some default options |
| 880 | signature_check_enabled = 0; |
Koushik K. Dutta | 2bda3e9 | 2010-03-06 16:40:52 -0800 | [diff] [blame] | 881 | script_assert_enabled = 0; |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 882 | is_user_initiated_recovery = 1; |
| 883 | ui_set_show_text(1); |
Koushik Dutta | 5d80817 | 2010-12-18 22:29:27 -0800 | [diff] [blame] | 884 | ui_set_background(BACKGROUND_ICON_CLOCKWORK); |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 885 | |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 886 | if (extendedcommand_file_exists()) { |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 887 | LOGI("Running extendedcommand...\n"); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 888 | int ret; |
| 889 | if (0 == (ret = run_and_remove_extendedcommand())) { |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 890 | status = INSTALL_SUCCESS; |
Koushik K. Dutta | 13d8fcc | 2010-03-07 14:15:14 -0800 | [diff] [blame] | 891 | ui_set_show_text(0); |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 892 | } |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 893 | else { |
| 894 | handle_failure(ret); |
| 895 | } |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 896 | } else { |
| 897 | LOGI("Skipping execution of extendedcommand, file not found...\n"); |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 898 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 901 | if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) ui_set_background(BACKGROUND_ICON_ERROR); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 902 | if (status != INSTALL_SUCCESS || ui_text_visible()) { |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 903 | prompt_and_wait(); |
| 904 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 905 | |
Koushik Dutta | 7f13e15 | 2011-09-08 16:55:35 -0700 | [diff] [blame] | 906 | // If there is a radio image pending, reboot now to install it. |
| 907 | maybe_install_firmware_update(send_intent); |
| 908 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 909 | // Otherwise, get ready to boot the main system... |
| 910 | finish_recovery(send_intent); |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame^] | 911 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 912 | sync(); |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame^] | 913 | if(!poweroff) { |
| 914 | ui_print("Rebooting...\n"); |
| 915 | android_reboot(ANDROID_RB_RESTART, 0, 0); |
| 916 | } |
| 917 | else { |
| 918 | ui_print("Shutting down...\n"); |
| 919 | android_reboot(ANDROID_RB_POWEROFF, 0, 0); |
| 920 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 921 | return EXIT_SUCCESS; |
| 922 | } |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 923 | |
| 924 | int get_allow_toggle_display() { |
| 925 | return allow_display_toggle; |
Chris Soyars | a1749d9 | 2010-02-26 02:45:55 -0500 | [diff] [blame] | 926 | } |