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 | |
Tao Bao | 6d99d4b | 2018-04-25 16:47:04 -0700 | [diff] [blame] | 17 | #include "private/recovery.h" |
| 18 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | #include <ctype.h> |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 20 | #include <dirent.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <getopt.h> |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 24 | #include <inttypes.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 25 | #include <limits.h> |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 26 | #include <linux/fs.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 27 | #include <linux/input.h> |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 28 | #include <stdarg.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
Patrick Tjin | cd055ee | 2014-12-09 11:26:40 -0800 | [diff] [blame] | 32 | #include <sys/klog.h> |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 33 | #include <sys/stat.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | #include <sys/types.h> |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 35 | #include <sys/wait.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 36 | #include <time.h> |
| 37 | #include <unistd.h> |
| 38 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 39 | #include <algorithm> |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 40 | #include <functional> |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 41 | #include <memory> |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 42 | #include <string> |
| 43 | #include <vector> |
Tao Bao | 04ca426 | 2015-09-10 15:32:24 -0700 | [diff] [blame] | 44 | |
Elliott Hughes | 4b166f0 | 2015-12-04 15:30:20 -0800 | [diff] [blame] | 45 | #include <android-base/file.h> |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 46 | #include <android-base/logging.h> |
Tianjie Xu | 3c62b67 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 47 | #include <android-base/parseint.h> |
Elliott Hughes | cb22040 | 2016-09-23 15:30:55 -0700 | [diff] [blame] | 48 | #include <android-base/properties.h> |
Elliott Hughes | 4b166f0 | 2015-12-04 15:30:20 -0800 | [diff] [blame] | 49 | #include <android-base/stringprintf.h> |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 50 | #include <android-base/strings.h> |
| 51 | #include <android-base/unique_fd.h> |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 52 | #include <bootloader_message/bootloader_message.h> |
Tao Bao | 7523863 | 2015-05-27 14:46:17 -0700 | [diff] [blame] | 53 | #include <cutils/android_reboot.h> |
Elliott Hughes | cb22040 | 2016-09-23 15:30:55 -0700 | [diff] [blame] | 54 | #include <cutils/properties.h> /* for property_list */ |
Elliott Hughes | 4bbd5bf | 2016-04-01 18:24:39 -0700 | [diff] [blame] | 55 | #include <healthd/BatteryMonitor.h> |
Tao Bao | e1905ad | 2017-03-22 14:57:04 -0700 | [diff] [blame] | 56 | #include <private/android_filesystem_config.h> /* for AID_SYSTEM */ |
Tao Bao | 6d99d4b | 2018-04-25 16:47:04 -0700 | [diff] [blame] | 57 | #include <private/android_logger.h> /* private pmsg functions */ |
Jeff Vander Stoep | e35926e | 2017-06-14 15:30:39 -0700 | [diff] [blame] | 58 | #include <selinux/android.h> |
Elliott Hughes | 4bbd5bf | 2016-04-01 18:24:39 -0700 | [diff] [blame] | 59 | #include <selinux/label.h> |
| 60 | #include <selinux/selinux.h> |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 61 | #include <ziparchive/zip_archive.h> |
Yabin Cui | 99281df | 2016-02-17 12:21:52 -0800 | [diff] [blame] | 62 | |
Tao Bao | 7523863 | 2015-05-27 14:46:17 -0700 | [diff] [blame] | 63 | #include "adb_install.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 64 | #include "common.h" |
Tao Bao | 7523863 | 2015-05-27 14:46:17 -0700 | [diff] [blame] | 65 | #include "device.h" |
| 66 | #include "fuse_sdcard_provider.h" |
| 67 | #include "fuse_sideload.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 68 | #include "install.h" |
| 69 | #include "minui/minui.h" |
Tao Bao | 17054c0 | 2018-05-03 22:41:23 -0700 | [diff] [blame^] | 70 | #include "otautil/dirutil.h" |
Tao Bao | 1fc5bf3 | 2017-10-06 07:43:41 -0700 | [diff] [blame] | 71 | #include "otautil/error_code.h" |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 72 | #include "otautil/paths.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 73 | #include "roots.h" |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 74 | #include "rotate_logs.h" |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 75 | #include "screen_ui.h" |
Sen Jiang | d530449 | 2016-12-09 16:20:49 -0800 | [diff] [blame] | 76 | #include "stub_ui.h" |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 77 | #include "ui.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 78 | |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 79 | static constexpr const char* CACHE_LOG_DIR = "/cache/recovery"; |
| 80 | static constexpr const char* COMMAND_FILE = "/cache/recovery/command"; |
| 81 | static constexpr const char* LOG_FILE = "/cache/recovery/log"; |
| 82 | static constexpr const char* LAST_INSTALL_FILE = "/cache/recovery/last_install"; |
| 83 | static constexpr const char* LAST_KMSG_FILE = "/cache/recovery/last_kmsg"; |
| 84 | static constexpr const char* LAST_LOG_FILE = "/cache/recovery/last_log"; |
| 85 | static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale"; |
Tianjie Xu | 06e57ac | 2016-07-11 14:04:08 -0700 | [diff] [blame] | 86 | |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 87 | static constexpr const char* CACHE_ROOT = "/cache"; |
| 88 | static constexpr const char* DATA_ROOT = "/data"; |
| 89 | static constexpr const char* METADATA_ROOT = "/metadata"; |
| 90 | static constexpr const char* SDCARD_ROOT = "/sdcard"; |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 91 | |
Tao Bao | bd0ddcd | 2017-05-04 13:03:18 -0700 | [diff] [blame] | 92 | // We define RECOVERY_API_VERSION in Android.mk, which will be picked up by build system and packed |
| 93 | // into target_files.zip. Assert the version defined in code and in Android.mk are consistent. |
| 94 | static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions."); |
| 95 | |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 96 | static std::string locale; |
Dan Albert | 8584fcf | 2016-10-27 03:08:08 +0000 | [diff] [blame] | 97 | static bool has_cache = false; |
Tao Bao | c0319b6 | 2016-10-13 15:17:04 -0700 | [diff] [blame] | 98 | |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 99 | RecoveryUI* ui = nullptr; |
| 100 | bool modified_flash = false; |
Tao Bao | a8d72bc | 2016-12-25 18:46:50 -0800 | [diff] [blame] | 101 | std::string stage; |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 102 | const char* reason = nullptr; |
| 103 | struct selabel_handle* sehandle; |
| 104 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 105 | /* |
| 106 | * The recovery tool communicates with the main system through /cache files. |
| 107 | * /cache/recovery/command - INPUT - command line for tool, one arg per line |
| 108 | * /cache/recovery/log - OUTPUT - combined log file from recovery run(s) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 109 | * |
| 110 | * The arguments which may be supplied in the recovery.command file: |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 111 | * --update_package=path - verify install an OTA package file |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 112 | * --wipe_data - erase user data (and cache), then reboot |
Tao Bao | f9f1734 | 2018-04-27 10:44:04 -0700 | [diff] [blame] | 113 | * --prompt_and_wipe_data - prompt the user that data is corrupt, with their consent erase user |
| 114 | * data (and cache), then reboot |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 115 | * --wipe_cache - wipe cache (but not user data), then reboot |
Tao Bao | f9f1734 | 2018-04-27 10:44:04 -0700 | [diff] [blame] | 116 | * --show_text - show the recovery text menu, used by some bootloader (e.g. http://b/36872519). |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 117 | * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 118 | * --just_exit - do nothing; exit and reboot |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 119 | * |
| 120 | * After completing, we remove /cache/recovery/command and reboot. |
| 121 | * Arguments may also be supplied in the bootloader control block (BCB). |
| 122 | * These important scenarios must be safely restartable at any point: |
| 123 | * |
| 124 | * FACTORY RESET |
| 125 | * 1. user selects "factory reset" |
| 126 | * 2. main system writes "--wipe_data" to /cache/recovery/command |
| 127 | * 3. main system reboots into recovery |
| 128 | * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data" |
| 129 | * -- after this, rebooting will restart the erase -- |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 130 | * 5. erase_volume() reformats /data |
| 131 | * 6. erase_volume() reformats /cache |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 132 | * 7. finish_recovery() erases BCB |
| 133 | * -- after this, rebooting will restart the main system -- |
| 134 | * 8. main() calls reboot() to boot main system |
| 135 | * |
| 136 | * OTA INSTALL |
| 137 | * 1. main system downloads OTA package to /cache/some-filename.zip |
Doug Zongker | 9b125b0 | 2010-09-22 12:01:37 -0700 | [diff] [blame] | 138 | * 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] | 139 | * 3. main system reboots into recovery |
| 140 | * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..." |
| 141 | * -- after this, rebooting will attempt to reinstall the update -- |
| 142 | * 5. install_package() attempts to install the update |
| 143 | * NOTE: the package install must itself be restartable from any point |
| 144 | * 6. finish_recovery() erases BCB |
| 145 | * -- after this, rebooting will (try to) restart the main system -- |
| 146 | * 7. ** if install failed ** |
| 147 | * 7a. prompt_and_wait() shows an error icon and waits for the user |
Tao Bao | c033639 | 2016-12-13 22:29:49 -0800 | [diff] [blame] | 148 | * 7b. the user reboots (pulling the battery, etc) into the main system |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 149 | */ |
| 150 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 151 | FILE* fopen_path(const std::string& path, const char* mode) { |
| 152 | if (ensure_path_mounted(path.c_str()) != 0) { |
Tao Bao | ac3d1ed | 2017-07-23 00:01:02 -0700 | [diff] [blame] | 153 | LOG(ERROR) << "Can't mount " << path; |
| 154 | return nullptr; |
| 155 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 156 | |
Tao Bao | ac3d1ed | 2017-07-23 00:01:02 -0700 | [diff] [blame] | 157 | // When writing, try to create the containing directory, if necessary. Use generous permissions, |
| 158 | // the system (init.rc) will reset them. |
| 159 | if (strchr("wa", mode[0])) { |
| 160 | mkdir_recursively(path, 0777, true, sehandle); |
| 161 | } |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 162 | return fopen(path.c_str(), mode); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Tao Bao | 6d99d4b | 2018-04-25 16:47:04 -0700 | [diff] [blame] | 165 | void check_and_fclose(FILE* fp, const std::string& name) { |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 166 | fflush(fp); |
| 167 | if (fsync(fileno(fp)) == -1) { |
| 168 | PLOG(ERROR) << "Failed to fsync " << name; |
| 169 | } |
| 170 | if (ferror(fp)) { |
| 171 | PLOG(ERROR) << "Error in " << name; |
| 172 | } |
| 173 | fclose(fp); |
Tao Bao | 04ca426 | 2015-09-10 15:32:24 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Elliott Hughes | f14af80 | 2015-02-10 14:46:14 -0800 | [diff] [blame] | 176 | bool is_ro_debuggable() { |
Elliott Hughes | cb22040 | 2016-09-23 15:30:55 -0700 | [diff] [blame] | 177 | return android::base::GetBoolProperty("ro.debuggable", false); |
Elliott Hughes | f14af80 | 2015-02-10 14:46:14 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Dmitri Plotnikov | 8706a98 | 2017-04-18 08:28:26 -0700 | [diff] [blame] | 180 | bool reboot(const std::string& command) { |
| 181 | std::string cmd = command; |
| 182 | if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { |
| 183 | cmd += ",quiescent"; |
| 184 | } |
| 185 | return android::base::SetProperty(ANDROID_RB_PROPERTY, cmd); |
| 186 | } |
| 187 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 188 | // command line args come from, in decreasing precedence: |
| 189 | // - the actual command line |
| 190 | // - the bootloader control block (one per line, after "recovery") |
| 191 | // - the contents of COMMAND_FILE (one per line) |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 192 | static std::vector<std::string> get_args(const int argc, char** const argv) { |
| 193 | CHECK_GT(argc, 0); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 194 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 195 | bootloader_message boot = {}; |
| 196 | std::string err; |
| 197 | if (!read_bootloader_message(&boot, &err)) { |
| 198 | LOG(ERROR) << err; |
| 199 | // If fails, leave a zeroed bootloader_message. |
| 200 | boot = {}; |
| 201 | } |
Tao Bao | a8d72bc | 2016-12-25 18:46:50 -0800 | [diff] [blame] | 202 | stage = std::string(boot.stage); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 203 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 204 | if (boot.command[0] != 0) { |
| 205 | std::string boot_command = std::string(boot.command, sizeof(boot.command)); |
| 206 | LOG(INFO) << "Boot command: " << boot_command; |
| 207 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 208 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 209 | if (boot.status[0] != 0) { |
| 210 | std::string boot_status = std::string(boot.status, sizeof(boot.status)); |
| 211 | LOG(INFO) << "Boot status: " << boot_status; |
| 212 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 213 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 214 | std::vector<std::string> args(argv, argv + argc); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 215 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 216 | // --- if arguments weren't supplied, look in the bootloader control block |
Tao Bao | 570af9d | 2017-01-09 10:29:59 -0800 | [diff] [blame] | 217 | if (args.size() == 1) { |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 218 | boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination |
| 219 | std::string boot_recovery(boot.recovery); |
| 220 | std::vector<std::string> tokens = android::base::Split(boot_recovery, "\n"); |
| 221 | if (!tokens.empty() && tokens[0] == "recovery") { |
| 222 | for (auto it = tokens.begin() + 1; it != tokens.end(); it++) { |
| 223 | // Skip empty and '\0'-filled tokens. |
| 224 | if (!it->empty() && (*it)[0] != '\0') args.push_back(std::move(*it)); |
| 225 | } |
| 226 | LOG(INFO) << "Got " << args.size() << " arguments from boot message"; |
| 227 | } else if (boot.recovery[0] != 0) { |
| 228 | LOG(ERROR) << "Bad boot message: \"" << boot_recovery << "\""; |
| 229 | } |
| 230 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 231 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 232 | // --- if that doesn't work, try the command file (if we have /cache). |
Tao Bao | 570af9d | 2017-01-09 10:29:59 -0800 | [diff] [blame] | 233 | if (args.size() == 1 && has_cache) { |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 234 | std::string content; |
Tao Bao | 7d34fa1 | 2016-12-08 18:10:48 -0800 | [diff] [blame] | 235 | if (ensure_path_mounted(COMMAND_FILE) == 0 && |
| 236 | android::base::ReadFileToString(COMMAND_FILE, &content)) { |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 237 | std::vector<std::string> tokens = android::base::Split(content, "\n"); |
Tao Bao | 7d34fa1 | 2016-12-08 18:10:48 -0800 | [diff] [blame] | 238 | // All the arguments in COMMAND_FILE are needed (unlike the BCB message, |
| 239 | // COMMAND_FILE doesn't use filename as the first argument). |
| 240 | for (auto it = tokens.begin(); it != tokens.end(); it++) { |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 241 | // Skip empty and '\0'-filled tokens. |
| 242 | if (!it->empty() && (*it)[0] != '\0') args.push_back(std::move(*it)); |
| 243 | } |
| 244 | LOG(INFO) << "Got " << args.size() << " arguments from " << COMMAND_FILE; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 245 | } |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 246 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 247 | |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 248 | // Write the arguments (excluding the filename in args[0]) back into the |
| 249 | // bootloader control block. So the device will always boot into recovery to |
| 250 | // finish the pending work, until finish_recovery() is called. |
| 251 | std::vector<std::string> options(args.cbegin() + 1, args.cend()); |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 252 | if (!update_bootloader_message(options, &err)) { |
| 253 | LOG(ERROR) << "Failed to set BCB message: " << err; |
Tao Bao | f0ed159 | 2016-12-02 11:32:19 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | return args; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 259 | // Set the BCB to reboot back into recovery (it won't resume the install from |
| 260 | // sdcard though). |
| 261 | static void set_sdcard_update_bootloader_message() { |
| 262 | std::vector<std::string> options; |
| 263 | std::string err; |
| 264 | if (!update_bootloader_message(options, &err)) { |
| 265 | LOG(ERROR) << "Failed to set BCB message: " << err; |
| 266 | } |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 267 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 268 | |
Tao Bao | bef3971 | 2015-05-04 18:50:27 -0700 | [diff] [blame] | 269 | // Read from kernel log into buffer and write out to file. |
| 270 | static void save_kernel_log(const char* destination) { |
| 271 | int klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0); |
Patrick Tjin | cd055ee | 2014-12-09 11:26:40 -0800 | [diff] [blame] | 272 | if (klog_buf_len <= 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 273 | PLOG(ERROR) << "Error getting klog size"; |
Patrick Tjin | cd055ee | 2014-12-09 11:26:40 -0800 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | |
Tao Bao | bef3971 | 2015-05-04 18:50:27 -0700 | [diff] [blame] | 277 | std::string buffer(klog_buf_len, 0); |
| 278 | int n = klogctl(KLOG_READ_ALL, &buffer[0], klog_buf_len); |
| 279 | if (n == -1) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 280 | PLOG(ERROR) << "Error in reading klog"; |
Patrick Tjin | cd055ee | 2014-12-09 11:26:40 -0800 | [diff] [blame] | 281 | return; |
| 282 | } |
Tao Bao | bef3971 | 2015-05-04 18:50:27 -0700 | [diff] [blame] | 283 | buffer.resize(n); |
| 284 | android::base::WriteStringToFile(buffer, destination); |
Patrick Tjin | cd055ee | 2014-12-09 11:26:40 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 287 | // Writes content to the current pmsg session. |
| 288 | static ssize_t __pmsg_write(const std::string& filename, const std::string& buf) { |
| 289 | return __android_log_pmsg_file_write(LOG_ID_SYSTEM, ANDROID_LOG_INFO, filename.c_str(), |
| 290 | buf.data(), buf.size()); |
Mark Salyzyn | a4f701a | 2016-03-09 14:58:16 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 293 | static void copy_log_file_to_pmsg(const std::string& source, const std::string& destination) { |
| 294 | std::string content; |
| 295 | android::base::ReadFileToString(source, &content); |
| 296 | __pmsg_write(destination, content); |
Mark Salyzyn | a4f701a | 2016-03-09 14:58:16 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Tao Bao | f012432 | 2015-04-11 02:04:11 +0000 | [diff] [blame] | 299 | // How much of the temp log we have copied to the copy in cache. |
Chih-Hung Hsieh | 54a2747 | 2016-04-18 11:30:55 -0700 | [diff] [blame] | 300 | static off_t tmplog_offset = 0; |
Tao Bao | f012432 | 2015-04-11 02:04:11 +0000 | [diff] [blame] | 301 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 302 | static void copy_log_file(const std::string& source, const std::string& destination, bool append) { |
Tianjie Xu | de6735e | 2017-07-10 15:13:33 -0700 | [diff] [blame] | 303 | FILE* dest_fp = fopen_path(destination, append ? "ae" : "we"); |
| 304 | if (dest_fp == nullptr) { |
| 305 | PLOG(ERROR) << "Can't open " << destination; |
| 306 | } else { |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 307 | FILE* source_fp = fopen(source.c_str(), "re"); |
Tianjie Xu | de6735e | 2017-07-10 15:13:33 -0700 | [diff] [blame] | 308 | if (source_fp != nullptr) { |
| 309 | if (append) { |
| 310 | fseeko(source_fp, tmplog_offset, SEEK_SET); // Since last write |
| 311 | } |
| 312 | char buf[4096]; |
| 313 | size_t bytes; |
| 314 | while ((bytes = fread(buf, 1, sizeof(buf), source_fp)) != 0) { |
| 315 | fwrite(buf, 1, bytes, dest_fp); |
| 316 | } |
| 317 | if (append) { |
| 318 | tmplog_offset = ftello(source_fp); |
| 319 | } |
| 320 | check_and_fclose(source_fp, source); |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 321 | } |
Tianjie Xu | de6735e | 2017-07-10 15:13:33 -0700 | [diff] [blame] | 322 | check_and_fclose(dest_fp, destination); |
| 323 | } |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 326 | static void copy_logs() { |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 327 | // We only rotate and record the log of the current session if there are actual attempts to modify |
| 328 | // the flash, such as wipes, installs from BCB or menu selections. This is to avoid unnecessary |
| 329 | // rotation (and possible deletion) of log files, if it does not do anything loggable. |
| 330 | if (!modified_flash) { |
| 331 | return; |
| 332 | } |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 333 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 334 | // Always write to pmsg, this allows the OTA logs to be caught in `logcat -L`. |
| 335 | copy_log_file_to_pmsg(Paths::Get().temporary_log_file(), LAST_LOG_FILE); |
| 336 | copy_log_file_to_pmsg(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE); |
Mark Salyzyn | a4f701a | 2016-03-09 14:58:16 -0800 | [diff] [blame] | 337 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 338 | // We can do nothing for now if there's no /cache partition. |
| 339 | if (!has_cache) { |
| 340 | return; |
| 341 | } |
Mark Salyzyn | a4f701a | 2016-03-09 14:58:16 -0800 | [diff] [blame] | 342 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 343 | ensure_path_mounted(LAST_LOG_FILE); |
| 344 | ensure_path_mounted(LAST_KMSG_FILE); |
| 345 | rotate_logs(LAST_LOG_FILE, LAST_KMSG_FILE); |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 346 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 347 | // Copy logs to cache so the system can find out what happened. |
| 348 | copy_log_file(Paths::Get().temporary_log_file(), LOG_FILE, true); |
| 349 | copy_log_file(Paths::Get().temporary_log_file(), LAST_LOG_FILE, false); |
| 350 | copy_log_file(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE, false); |
| 351 | save_kernel_log(LAST_KMSG_FILE); |
| 352 | chmod(LOG_FILE, 0600); |
| 353 | chown(LOG_FILE, AID_SYSTEM, AID_SYSTEM); |
| 354 | chmod(LAST_KMSG_FILE, 0600); |
| 355 | chown(LAST_KMSG_FILE, AID_SYSTEM, AID_SYSTEM); |
| 356 | chmod(LAST_LOG_FILE, 0640); |
| 357 | chmod(LAST_INSTALL_FILE, 0644); |
| 358 | sync(); |
Doug Zongker | f24fd7e | 2013-07-02 11:43:25 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 361 | // Clear the recovery command and prepare to boot a (hopefully working) system, |
Tianjie Xu | c14d95d | 2016-03-24 11:50:34 -0700 | [diff] [blame] | 362 | // copy our log file to cache as well (for the system to read). This function is |
| 363 | // idempotent: call it as many times as you like. |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 364 | static void finish_recovery() { |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 365 | // Save the locale to cache, so if recovery is next started up without a '--locale' argument |
| 366 | // (e.g., directly from the bootloader) it will use the last-known locale. |
| 367 | if (!locale.empty() && has_cache) { |
| 368 | LOG(INFO) << "Saving locale \"" << locale << "\""; |
| 369 | if (ensure_path_mounted(LOCALE_FILE) != 0) { |
| 370 | LOG(ERROR) << "Failed to mount " << LOCALE_FILE; |
| 371 | } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) { |
| 372 | PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE; |
Doug Zongker | 4f33e55 | 2012-08-23 13:16:12 -0700 | [diff] [blame] | 373 | } |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 374 | } |
Doug Zongker | 4f33e55 | 2012-08-23 13:16:12 -0700 | [diff] [blame] | 375 | |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 376 | copy_logs(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 377 | |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 378 | // Reset to normal system boot so recovery won't cycle indefinitely. |
| 379 | std::string err; |
| 380 | if (!clear_bootloader_message(&err)) { |
| 381 | LOG(ERROR) << "Failed to clear BCB message: " << err; |
| 382 | } |
| 383 | |
| 384 | // Remove the command file, so recovery won't repeat indefinitely. |
| 385 | if (has_cache) { |
| 386 | if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) { |
| 387 | LOG(WARNING) << "Can't unlink " << COMMAND_FILE; |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 388 | } |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 389 | ensure_path_unmounted(CACHE_ROOT); |
| 390 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 391 | |
Tao Bao | ec57903 | 2017-07-21 12:13:15 -0700 | [diff] [blame] | 392 | sync(); // For good measure. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 395 | struct saved_log_file { |
| 396 | std::string name; |
| 397 | struct stat sb; |
| 398 | std::string data; |
| 399 | }; |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 400 | |
Elliott Hughes | 945548e | 2015-06-05 17:59:56 -0700 | [diff] [blame] | 401 | static bool erase_volume(const char* volume) { |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 402 | bool is_cache = (strcmp(volume, CACHE_ROOT) == 0); |
| 403 | bool is_data = (strcmp(volume, DATA_ROOT) == 0); |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 404 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 405 | ui->SetBackground(RecoveryUI::ERASING); |
| 406 | ui->SetProgressType(RecoveryUI::INDETERMINATE); |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 407 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 408 | std::vector<saved_log_file> log_files; |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 409 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 410 | if (is_cache) { |
| 411 | // If we're reformatting /cache, we load any past logs |
| 412 | // (i.e. "/cache/recovery/last_*") and the current log |
| 413 | // ("/cache/recovery/log") into memory, so we can restore them after |
| 414 | // the reformat. |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 415 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 416 | ensure_path_mounted(volume); |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 417 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 418 | struct dirent* de; |
| 419 | std::unique_ptr<DIR, decltype(&closedir)> d(opendir(CACHE_LOG_DIR), closedir); |
| 420 | if (d) { |
| 421 | while ((de = readdir(d.get())) != nullptr) { |
| 422 | if (strncmp(de->d_name, "last_", 5) == 0 || strcmp(de->d_name, "log") == 0) { |
| 423 | std::string path = android::base::StringPrintf("%s/%s", CACHE_LOG_DIR, de->d_name); |
| 424 | |
| 425 | struct stat sb; |
| 426 | if (stat(path.c_str(), &sb) == 0) { |
| 427 | // truncate files to 512kb |
| 428 | if (sb.st_size > (1 << 19)) { |
| 429 | sb.st_size = 1 << 19; |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 430 | } |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 431 | |
| 432 | std::string data(sb.st_size, '\0'); |
Tianjie Xu | de6735e | 2017-07-10 15:13:33 -0700 | [diff] [blame] | 433 | FILE* f = fopen(path.c_str(), "rbe"); |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 434 | fread(&data[0], 1, data.size(), f); |
| 435 | fclose(f); |
| 436 | |
| 437 | log_files.emplace_back(saved_log_file{ path, sb, data }); |
| 438 | } |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 439 | } |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 440 | } |
Paul Lawrence | d0db337 | 2015-11-05 13:38:40 -0800 | [diff] [blame] | 441 | } else { |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 442 | if (errno != ENOENT) { |
| 443 | PLOG(ERROR) << "Failed to opendir " << CACHE_LOG_DIR; |
| 444 | } |
Paul Lawrence | d0db337 | 2015-11-05 13:38:40 -0800 | [diff] [blame] | 445 | } |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 446 | } |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 447 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 448 | ui->Print("Formatting %s...\n", volume); |
| 449 | |
| 450 | ensure_path_unmounted(volume); |
| 451 | |
| 452 | int result; |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 453 | if (is_data && reason && strcmp(reason, "convert_fbe") == 0) { |
Tao Bao | 406a6ff | 2018-04-30 10:05:57 -0700 | [diff] [blame] | 454 | static constexpr const char* CONVERT_FBE_DIR = "/tmp/convert_fbe"; |
| 455 | static constexpr const char* CONVERT_FBE_FILE = "/tmp/convert_fbe/convert_fbe"; |
| 456 | // Create convert_fbe breadcrumb file to signal init to convert to file based encryption, not |
| 457 | // full disk encryption. |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 458 | if (mkdir(CONVERT_FBE_DIR, 0700) != 0) { |
Tao Bao | 406a6ff | 2018-04-30 10:05:57 -0700 | [diff] [blame] | 459 | PLOG(ERROR) << "Failed to mkdir " << CONVERT_FBE_DIR; |
| 460 | return false; |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 461 | } |
Tianjie Xu | de6735e | 2017-07-10 15:13:33 -0700 | [diff] [blame] | 462 | FILE* f = fopen(CONVERT_FBE_FILE, "wbe"); |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 463 | if (!f) { |
Tao Bao | 406a6ff | 2018-04-30 10:05:57 -0700 | [diff] [blame] | 464 | PLOG(ERROR) << "Failed to convert to file encryption"; |
| 465 | return false; |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 466 | } |
| 467 | fclose(f); |
| 468 | result = format_volume(volume, CONVERT_FBE_DIR); |
| 469 | remove(CONVERT_FBE_FILE); |
| 470 | rmdir(CONVERT_FBE_DIR); |
| 471 | } else { |
| 472 | result = format_volume(volume); |
| 473 | } |
| 474 | |
| 475 | if (is_cache) { |
| 476 | // Re-create the log dir and write back the log entries. |
| 477 | if (ensure_path_mounted(CACHE_LOG_DIR) == 0 && |
Tao Bao | ac3d1ed | 2017-07-23 00:01:02 -0700 | [diff] [blame] | 478 | mkdir_recursively(CACHE_LOG_DIR, 0777, false, sehandle) == 0) { |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 479 | for (const auto& log : log_files) { |
| 480 | if (!android::base::WriteStringToFile(log.data, log.name, log.sb.st_mode, log.sb.st_uid, |
| 481 | log.sb.st_gid)) { |
| 482 | PLOG(ERROR) << "Failed to write to " << log.name; |
Doug Zongker | 6d0d7ac | 2013-07-09 13:34:55 -0700 | [diff] [blame] | 483 | } |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 484 | } |
| 485 | } else { |
| 486 | PLOG(ERROR) << "Failed to mount / create " << CACHE_LOG_DIR; |
Doug Zongker | 2c3539e | 2010-09-29 13:21:30 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Tao Bao | 3f5a382 | 2016-12-13 11:14:37 -0800 | [diff] [blame] | 489 | // Any part of the log we'd copied to cache is now gone. |
| 490 | // Reset the pointer so we copy from the beginning of the temp |
| 491 | // log. |
| 492 | tmplog_offset = 0; |
| 493 | copy_logs(); |
| 494 | } |
| 495 | |
| 496 | return (result == 0); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 499 | // Returns the selected filename, or an empty string. |
| 500 | static std::string browse_directory(const std::string& path, Device* device) { |
| 501 | ensure_path_mounted(path.c_str()); |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 502 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 503 | std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path.c_str()), closedir); |
| 504 | if (!d) { |
| 505 | PLOG(ERROR) << "error opening " << path; |
| 506 | return ""; |
| 507 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 508 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 509 | std::vector<std::string> dirs; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 510 | std::vector<std::string> entries{ "../" }; // "../" is always the first entry. |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 511 | |
| 512 | dirent* de; |
| 513 | while ((de = readdir(d.get())) != nullptr) { |
| 514 | std::string name(de->d_name); |
| 515 | |
| 516 | if (de->d_type == DT_DIR) { |
| 517 | // Skip "." and ".." entries. |
| 518 | if (name == "." || name == "..") continue; |
| 519 | dirs.push_back(name + "/"); |
| 520 | } else if (de->d_type == DT_REG && android::base::EndsWithIgnoreCase(name, ".zip")) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 521 | entries.push_back(name); |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | std::sort(dirs.begin(), dirs.end()); |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 526 | std::sort(entries.begin(), entries.end()); |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 527 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 528 | // Append dirs to the entries list. |
| 529 | entries.insert(entries.end(), dirs.begin(), dirs.end()); |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 530 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 531 | std::vector<std::string> headers{ "Choose a package to install:", path }; |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 532 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 533 | size_t chosen_item = 0; |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 534 | while (true) { |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 535 | chosen_item = ui->ShowMenu( |
| 536 | headers, entries, chosen_item, true, |
| 537 | std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 538 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 539 | const std::string& item = entries[chosen_item]; |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 540 | if (chosen_item == 0) { |
| 541 | // Go up but continue browsing (if the caller is browse_directory). |
| 542 | return ""; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 545 | std::string new_path = path + "/" + item; |
| 546 | if (new_path.back() == '/') { |
| 547 | // Recurse down into a subdirectory. |
| 548 | new_path.pop_back(); |
| 549 | std::string result = browse_directory(new_path, device); |
| 550 | if (!result.empty()) return result; |
| 551 | } else { |
| 552 | // Selected a zip file: return the path to the caller. |
| 553 | return new_path; |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 554 | } |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 555 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 556 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 557 | // Unreachable. |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Elliott Hughes | 30694c9 | 2015-03-25 15:16:51 -0700 | [diff] [blame] | 560 | static bool yes_no(Device* device, const char* question1, const char* question2) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 561 | std::vector<std::string> headers{ question1, question2 }; |
| 562 | std::vector<std::string> items{ " No", " Yes" }; |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 563 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 564 | size_t chosen_item = ui->ShowMenu( |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 565 | headers, items, 0, true, |
| 566 | std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); |
| 567 | return (chosen_item == 1); |
Elliott Hughes | 30694c9 | 2015-03-25 15:16:51 -0700 | [diff] [blame] | 568 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 569 | |
Paul Crowley | 08404b4 | 2016-12-19 13:04:23 -0800 | [diff] [blame] | 570 | static bool ask_to_wipe_data(Device* device) { |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 571 | return yes_no(device, "Wipe all user data?", " THIS CAN NOT BE UNDONE!"); |
Paul Crowley | 08404b4 | 2016-12-19 13:04:23 -0800 | [diff] [blame] | 572 | } |
Doug Zongker | 1066d2c | 2009-04-01 13:57:40 -0700 | [diff] [blame] | 573 | |
Paul Crowley | 08404b4 | 2016-12-19 13:04:23 -0800 | [diff] [blame] | 574 | // Return true on success. |
| 575 | static bool wipe_data(Device* device) { |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 576 | modified_flash = true; |
| 577 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 578 | ui->Print("\n-- Wiping data...\n"); |
Paul Crowley | 3b4d516 | 2016-06-08 13:51:41 -0700 | [diff] [blame] | 579 | bool success = device->PreWipeData(); |
| 580 | if (success) { |
| 581 | success &= erase_volume(DATA_ROOT); |
| 582 | if (has_cache) { |
| 583 | success &= erase_volume(CACHE_ROOT); |
| 584 | } |
| 585 | if (volume_for_mount_point(METADATA_ROOT) != nullptr) { |
| 586 | success &= erase_volume(METADATA_ROOT); |
| 587 | } |
| 588 | } |
| 589 | if (success) { |
| 590 | success &= device->PostWipeData(); |
| 591 | } |
Elliott Hughes | 945548e | 2015-06-05 17:59:56 -0700 | [diff] [blame] | 592 | ui->Print("Data wipe %s.\n", success ? "complete" : "failed"); |
| 593 | return success; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Paul Crowley | 08404b4 | 2016-12-19 13:04:23 -0800 | [diff] [blame] | 596 | static bool prompt_and_wipe_data(Device* device) { |
Tao Bao | 2bbc6d6 | 2017-08-13 23:48:55 -0700 | [diff] [blame] | 597 | // Use a single string and let ScreenRecoveryUI handles the wrapping. |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 598 | std::vector<std::string> headers{ |
Tao Bao | 2bbc6d6 | 2017-08-13 23:48:55 -0700 | [diff] [blame] | 599 | "Can't load Android system. Your data may be corrupt. " |
| 600 | "If you continue to get this message, you may need to " |
| 601 | "perform a factory data reset and erase all user data " |
Paul Crowley | 31ac0c6 | 2017-03-23 12:32:40 -0700 | [diff] [blame] | 602 | "stored on this device.", |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 603 | }; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 604 | // clang-format off |
| 605 | std::vector<std::string> items { |
Paul Crowley | 31ac0c6 | 2017-03-23 12:32:40 -0700 | [diff] [blame] | 606 | "Try again", |
| 607 | "Factory data reset", |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 608 | }; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 609 | // clang-format on |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 610 | for (;;) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 611 | size_t chosen_item = ui->ShowMenu( |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 612 | headers, items, 0, true, |
| 613 | std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 614 | if (chosen_item != 1) { |
| 615 | return true; // Just reboot, no wipe; not a failure, user asked for it |
Paul Crowley | 08404b4 | 2016-12-19 13:04:23 -0800 | [diff] [blame] | 616 | } |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 617 | if (ask_to_wipe_data(device)) { |
| 618 | return wipe_data(device); |
| 619 | } |
| 620 | } |
Paul Crowley | 08404b4 | 2016-12-19 13:04:23 -0800 | [diff] [blame] | 621 | } |
| 622 | |
Tao Bao | e39a9bc | 2015-03-31 12:19:05 -0700 | [diff] [blame] | 623 | // Return true on success. |
| 624 | static bool wipe_cache(bool should_confirm, Device* device) { |
Tao Bao | 26112e5 | 2016-02-25 12:29:40 -0800 | [diff] [blame] | 625 | if (!has_cache) { |
| 626 | ui->Print("No /cache partition found.\n"); |
| 627 | return false; |
| 628 | } |
| 629 | |
Elliott Hughes | 30694c9 | 2015-03-25 15:16:51 -0700 | [diff] [blame] | 630 | if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) { |
Tao Bao | e39a9bc | 2015-03-31 12:19:05 -0700 | [diff] [blame] | 631 | return false; |
Elliott Hughes | 30694c9 | 2015-03-25 15:16:51 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 634 | modified_flash = true; |
| 635 | |
Elliott Hughes | 30694c9 | 2015-03-25 15:16:51 -0700 | [diff] [blame] | 636 | ui->Print("\n-- Wiping cache...\n"); |
Elliott Hughes | 945548e | 2015-06-05 17:59:56 -0700 | [diff] [blame] | 637 | bool success = erase_volume("/cache"); |
| 638 | ui->Print("Cache wipe %s.\n", success ? "complete" : "failed"); |
| 639 | return success; |
Elliott Hughes | 30694c9 | 2015-03-25 15:16:51 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 642 | // Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. Otherwise, it goes with |
| 643 | // BLKDISCARD (if device supports BLKDISCARDZEROES) or BLKZEROOUT. |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 644 | static bool secure_wipe_partition(const std::string& partition) { |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 645 | android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY))); |
| 646 | if (fd == -1) { |
| 647 | PLOG(ERROR) << "Failed to open \"" << partition << "\""; |
| 648 | return false; |
| 649 | } |
| 650 | |
| 651 | uint64_t range[2] = { 0, 0 }; |
| 652 | if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { |
| 653 | PLOG(ERROR) << "Failed to get partition size"; |
| 654 | return false; |
| 655 | } |
| 656 | LOG(INFO) << "Secure-wiping \"" << partition << "\" from " << range[0] << " to " << range[1]; |
| 657 | |
| 658 | LOG(INFO) << " Trying BLKSECDISCARD..."; |
| 659 | if (ioctl(fd, BLKSECDISCARD, &range) == -1) { |
| 660 | PLOG(WARNING) << " Failed"; |
| 661 | |
| 662 | // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT. |
| 663 | unsigned int zeroes; |
| 664 | if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) { |
| 665 | LOG(INFO) << " Trying BLKDISCARD..."; |
| 666 | if (ioctl(fd, BLKDISCARD, &range) == -1) { |
| 667 | PLOG(ERROR) << " Failed"; |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 668 | return false; |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 669 | } |
| 670 | } else { |
| 671 | LOG(INFO) << " Trying BLKZEROOUT..."; |
| 672 | if (ioctl(fd, BLKZEROOUT, &range) == -1) { |
| 673 | PLOG(ERROR) << " Failed"; |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 674 | return false; |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 675 | } |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 676 | } |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 677 | } |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 678 | |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 679 | LOG(INFO) << " Done"; |
| 680 | return true; |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Yabin Cui | fd99a31 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 683 | // Check if the wipe package matches expectation: |
| 684 | // 1. verify the package. |
| 685 | // 2. check metadata (ota-type, pre-device and serial number if having one). |
| 686 | static bool check_wipe_package(size_t wipe_package_size) { |
| 687 | if (wipe_package_size == 0) { |
| 688 | LOG(ERROR) << "wipe_package_size is zero"; |
| 689 | return false; |
| 690 | } |
| 691 | std::string wipe_package; |
| 692 | std::string err_str; |
| 693 | if (!read_wipe_package(&wipe_package, wipe_package_size, &err_str)) { |
| 694 | PLOG(ERROR) << "Failed to read wipe package"; |
| 695 | return false; |
| 696 | } |
| 697 | if (!verify_package(reinterpret_cast<const unsigned char*>(wipe_package.data()), |
| 698 | wipe_package.size())) { |
| 699 | LOG(ERROR) << "Failed to verify package"; |
| 700 | return false; |
| 701 | } |
| 702 | |
| 703 | // Extract metadata |
| 704 | ZipArchiveHandle zip; |
Tao Bao | efc3559 | 2017-01-08 22:45:47 -0800 | [diff] [blame] | 705 | int err = OpenArchiveFromMemory(static_cast<void*>(&wipe_package[0]), wipe_package.size(), |
| 706 | "wipe_package", &zip); |
Yabin Cui | fd99a31 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 707 | if (err != 0) { |
| 708 | LOG(ERROR) << "Can't open wipe package : " << ErrorCodeString(err); |
| 709 | return false; |
| 710 | } |
| 711 | std::string metadata; |
Tao Bao | 1b2a98b | 2017-03-24 10:45:34 -0700 | [diff] [blame] | 712 | if (!read_metadata_from_package(zip, &metadata)) { |
Yabin Cui | fd99a31 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 713 | CloseArchive(zip); |
| 714 | return false; |
| 715 | } |
| 716 | CloseArchive(zip); |
| 717 | |
| 718 | // Check metadata |
| 719 | std::vector<std::string> lines = android::base::Split(metadata, "\n"); |
| 720 | bool ota_type_matched = false; |
| 721 | bool device_type_matched = false; |
| 722 | bool has_serial_number = false; |
| 723 | bool serial_number_matched = false; |
| 724 | for (const auto& line : lines) { |
| 725 | if (line == "ota-type=BRICK") { |
| 726 | ota_type_matched = true; |
| 727 | } else if (android::base::StartsWith(line, "pre-device=")) { |
| 728 | std::string device_type = line.substr(strlen("pre-device=")); |
Tao Bao | efc3559 | 2017-01-08 22:45:47 -0800 | [diff] [blame] | 729 | std::string real_device_type = android::base::GetProperty("ro.build.product", ""); |
Yabin Cui | fd99a31 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 730 | device_type_matched = (device_type == real_device_type); |
| 731 | } else if (android::base::StartsWith(line, "serialno=")) { |
| 732 | std::string serial_no = line.substr(strlen("serialno=")); |
Tao Bao | efc3559 | 2017-01-08 22:45:47 -0800 | [diff] [blame] | 733 | std::string real_serial_no = android::base::GetProperty("ro.serialno", ""); |
Yabin Cui | fd99a31 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 734 | has_serial_number = true; |
| 735 | serial_number_matched = (serial_no == real_serial_no); |
| 736 | } |
| 737 | } |
| 738 | return ota_type_matched && device_type_matched && (!has_serial_number || serial_number_matched); |
| 739 | } |
| 740 | |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 741 | // Wipes the current A/B device, with a secure wipe of all the partitions in RECOVERY_WIPE. |
Yabin Cui | fd99a31 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 742 | static bool wipe_ab_device(size_t wipe_package_size) { |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 743 | ui->SetBackground(RecoveryUI::ERASING); |
| 744 | ui->SetProgressType(RecoveryUI::INDETERMINATE); |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 745 | |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 746 | if (!check_wipe_package(wipe_package_size)) { |
| 747 | LOG(ERROR) << "Failed to verify wipe package"; |
| 748 | return false; |
| 749 | } |
| 750 | static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe"; |
| 751 | std::string partition_list; |
| 752 | if (!android::base::ReadFileToString(RECOVERY_WIPE, &partition_list)) { |
| 753 | LOG(ERROR) << "failed to read \"" << RECOVERY_WIPE << "\""; |
| 754 | return false; |
| 755 | } |
| 756 | |
| 757 | std::vector<std::string> lines = android::base::Split(partition_list, "\n"); |
| 758 | for (const std::string& line : lines) { |
| 759 | std::string partition = android::base::Trim(line); |
| 760 | // Ignore '#' comment or empty lines. |
| 761 | if (android::base::StartsWith(partition, "#") || partition.empty()) { |
| 762 | continue; |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 765 | // Proceed anyway even if it fails to wipe some partition. |
| 766 | secure_wipe_partition(partition); |
| 767 | } |
| 768 | return true; |
Tao Bao | 862a4c1 | 2016-06-02 11:16:50 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 771 | static void choose_recovery_file(Device* device) { |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 772 | std::vector<std::string> entries; |
| 773 | if (has_cache) { |
| 774 | for (int i = 0; i < KEEP_LOG_COUNT; i++) { |
| 775 | auto add_to_entries = [&](const char* filename) { |
| 776 | std::string log_file(filename); |
| 777 | if (i > 0) { |
| 778 | log_file += "." + std::to_string(i); |
Tao Bao | bef3971 | 2015-05-04 18:50:27 -0700 | [diff] [blame] | 779 | } |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 780 | |
| 781 | if (ensure_path_mounted(log_file.c_str()) == 0 && access(log_file.c_str(), R_OK) == 0) { |
| 782 | entries.push_back(std::move(log_file)); |
| 783 | } |
| 784 | }; |
| 785 | |
| 786 | // Add LAST_LOG_FILE + LAST_LOG_FILE.x |
| 787 | add_to_entries(LAST_LOG_FILE); |
| 788 | |
| 789 | // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x |
| 790 | add_to_entries(LAST_KMSG_FILE); |
| 791 | } |
| 792 | } else { |
| 793 | // If cache partition is not found, view /tmp/recovery.log instead. |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 794 | if (access(Paths::Get().temporary_log_file().c_str(), R_OK) == -1) { |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 795 | return; |
Tianjie Xu | a54f75e | 2016-08-17 12:02:46 -0700 | [diff] [blame] | 796 | } else { |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 797 | entries.push_back(Paths::Get().temporary_log_file()); |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 798 | } |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 799 | } |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 800 | |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 801 | entries.push_back("Back"); |
Elliott Hughes | c049163 | 2015-05-06 12:40:05 -0700 | [diff] [blame] | 802 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 803 | std::vector<std::string> headers{ "Select file to view" }; |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 804 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 805 | size_t chosen_item = 0; |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 806 | while (true) { |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 807 | chosen_item = ui->ShowMenu( |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 808 | headers, entries, chosen_item, true, |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 809 | std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 810 | if (entries[chosen_item] == "Back") break; |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 811 | |
Tao Bao | 1d156b9 | 2018-05-02 12:43:18 -0700 | [diff] [blame] | 812 | ui->ShowFile(entries[chosen_item]); |
Tao Bao | 08fc6be | 2017-03-07 00:56:27 -0800 | [diff] [blame] | 813 | } |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 816 | static void run_graphics_test() { |
| 817 | // Switch to graphics screen. |
| 818 | ui->ShowText(false); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 819 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 820 | ui->SetProgressType(RecoveryUI::INDETERMINATE); |
| 821 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
| 822 | sleep(1); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 823 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 824 | ui->SetBackground(RecoveryUI::ERROR); |
| 825 | sleep(1); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 826 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 827 | ui->SetBackground(RecoveryUI::NO_COMMAND); |
| 828 | sleep(1); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 829 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 830 | ui->SetBackground(RecoveryUI::ERASING); |
| 831 | sleep(1); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 832 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 833 | // Calling SetBackground() after SetStage() to trigger a redraw. |
| 834 | ui->SetStage(1, 3); |
| 835 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
| 836 | sleep(1); |
| 837 | ui->SetStage(2, 3); |
| 838 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
| 839 | sleep(1); |
| 840 | ui->SetStage(3, 3); |
| 841 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
| 842 | sleep(1); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 843 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 844 | ui->SetStage(-1, -1); |
| 845 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 846 | |
Tao Bao | db7e898 | 2017-03-06 23:53:16 -0800 | [diff] [blame] | 847 | ui->SetProgressType(RecoveryUI::DETERMINATE); |
| 848 | ui->ShowProgress(1.0, 10.0); |
| 849 | float fraction = 0.0; |
| 850 | for (size_t i = 0; i < 100; ++i) { |
| 851 | fraction += .01; |
| 852 | ui->SetProgress(fraction); |
| 853 | usleep(100000); |
| 854 | } |
| 855 | |
| 856 | ui->ShowText(true); |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 859 | // How long (in seconds) we wait for the fuse-provided package file to |
| 860 | // appear, before timing out. |
| 861 | #define SDCARD_INSTALL_TIMEOUT 10 |
| 862 | |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 863 | static int apply_from_sdcard(Device* device, bool* wipe_cache) { |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 864 | modified_flash = true; |
| 865 | |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 866 | if (ensure_path_mounted(SDCARD_ROOT) != 0) { |
| 867 | ui->Print("\n-- Couldn't mount %s.\n", SDCARD_ROOT); |
| 868 | return INSTALL_ERROR; |
| 869 | } |
| 870 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 871 | std::string path = browse_directory(SDCARD_ROOT, device); |
| 872 | if (path.empty()) { |
Elliott Hughes | 018ed31 | 2015-04-08 16:51:36 -0700 | [diff] [blame] | 873 | ui->Print("\n-- No package file selected.\n"); |
caozhiyuan | b4effb9 | 2015-06-10 16:46:38 +0800 | [diff] [blame] | 874 | ensure_path_unmounted(SDCARD_ROOT); |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 875 | return INSTALL_ERROR; |
| 876 | } |
| 877 | |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 878 | ui->Print("\n-- Install %s ...\n", path.c_str()); |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 879 | set_sdcard_update_bootloader_message(); |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 880 | |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 881 | // We used to use fuse in a thread as opposed to a process. Since accessing |
| 882 | // through fuse involves going from kernel to userspace to kernel, it leads |
| 883 | // to deadlock when a page fault occurs. (Bug: 26313124) |
| 884 | pid_t child; |
| 885 | if ((child = fork()) == 0) { |
Tao Bao | c4a18ef | 2017-02-10 00:13:30 -0800 | [diff] [blame] | 886 | bool status = start_sdcard_fuse(path.c_str()); |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 887 | |
| 888 | _exit(status ? EXIT_SUCCESS : EXIT_FAILURE); |
| 889 | } |
| 890 | |
| 891 | // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the fuse in child |
| 892 | // process is ready. |
| 893 | int result = INSTALL_ERROR; |
| 894 | int status; |
| 895 | bool waited = false; |
| 896 | for (int i = 0; i < SDCARD_INSTALL_TIMEOUT; ++i) { |
| 897 | if (waitpid(child, &status, WNOHANG) == -1) { |
| 898 | result = INSTALL_ERROR; |
| 899 | waited = true; |
| 900 | break; |
| 901 | } |
| 902 | |
| 903 | struct stat sb; |
| 904 | if (stat(FUSE_SIDELOAD_HOST_PATHNAME, &sb) == -1) { |
| 905 | if (errno == ENOENT && i < SDCARD_INSTALL_TIMEOUT-1) { |
| 906 | sleep(1); |
| 907 | continue; |
| 908 | } else { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 909 | LOG(ERROR) << "Timed out waiting for the fuse-provided package."; |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 910 | result = INSTALL_ERROR; |
| 911 | kill(child, SIGKILL); |
| 912 | break; |
| 913 | } |
| 914 | } |
| 915 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 916 | result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, false, 0 /*retry_count*/); |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 917 | break; |
| 918 | } |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 919 | |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 920 | if (!waited) { |
| 921 | // Calling stat() on this magic filename signals the fuse |
| 922 | // filesystem to shut down. |
| 923 | struct stat sb; |
| 924 | stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &sb); |
| 925 | |
| 926 | waitpid(child, &status, 0); |
| 927 | } |
| 928 | |
| 929 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 930 | LOG(ERROR) << "Error exit from the fuse process: " << WEXITSTATUS(status); |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 931 | } |
| 932 | |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 933 | ensure_path_unmounted(SDCARD_ROOT); |
Tao Bao | cdcf28f | 2016-01-13 15:05:20 -0800 | [diff] [blame] | 934 | return result; |
Christian Poetzsch | 4ec58a4 | 2015-02-19 10:42:39 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 937 | // Returns REBOOT, SHUTDOWN, or REBOOT_BOOTLOADER. Returning NO_ACTION means to take the default, |
| 938 | // which is to reboot or shutdown depending on if the --shutdown_after flag was passed to recovery. |
| 939 | static Device::BuiltinAction prompt_and_wait(Device* device, int status) { |
| 940 | for (;;) { |
| 941 | finish_recovery(); |
| 942 | switch (status) { |
| 943 | case INSTALL_SUCCESS: |
| 944 | case INSTALL_NONE: |
| 945 | ui->SetBackground(RecoveryUI::NO_COMMAND); |
| 946 | break; |
Doug Zongker | 6c8553d | 2012-09-24 10:40:47 -0700 | [diff] [blame] | 947 | |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 948 | case INSTALL_ERROR: |
| 949 | case INSTALL_CORRUPT: |
| 950 | ui->SetBackground(RecoveryUI::ERROR); |
| 951 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 952 | } |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 953 | ui->SetProgressType(RecoveryUI::EMPTY); |
| 954 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 955 | size_t chosen_item = ui->ShowMenu( |
| 956 | {}, device->GetMenuItems(), 0, false, |
Tao Bao | 3aec696 | 2018-04-20 09:24:58 -0700 | [diff] [blame] | 957 | std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 958 | |
| 959 | // Device-specific code may take some action here. It may return one of the core actions |
| 960 | // handled in the switch statement below. |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 961 | Device::BuiltinAction chosen_action = (chosen_item == static_cast<size_t>(-1)) |
| 962 | ? Device::REBOOT |
| 963 | : device->InvokeMenuItem(chosen_item); |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 964 | |
| 965 | bool should_wipe_cache = false; |
| 966 | switch (chosen_action) { |
| 967 | case Device::NO_ACTION: |
| 968 | break; |
| 969 | |
| 970 | case Device::REBOOT: |
| 971 | case Device::SHUTDOWN: |
| 972 | case Device::REBOOT_BOOTLOADER: |
| 973 | return chosen_action; |
| 974 | |
| 975 | case Device::WIPE_DATA: |
| 976 | if (ui->IsTextVisible()) { |
| 977 | if (ask_to_wipe_data(device)) { |
| 978 | wipe_data(device); |
| 979 | } |
| 980 | } else { |
| 981 | wipe_data(device); |
| 982 | return Device::NO_ACTION; |
| 983 | } |
| 984 | break; |
| 985 | |
| 986 | case Device::WIPE_CACHE: |
| 987 | wipe_cache(ui->IsTextVisible(), device); |
| 988 | if (!ui->IsTextVisible()) return Device::NO_ACTION; |
| 989 | break; |
| 990 | |
| 991 | case Device::APPLY_ADB_SIDELOAD: |
| 992 | case Device::APPLY_SDCARD: |
| 993 | { |
| 994 | bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD); |
| 995 | if (adb) { |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 996 | status = apply_from_adb(&should_wipe_cache); |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 997 | } else { |
| 998 | status = apply_from_sdcard(device, &should_wipe_cache); |
| 999 | } |
| 1000 | |
| 1001 | if (status == INSTALL_SUCCESS && should_wipe_cache) { |
| 1002 | if (!wipe_cache(false, device)) { |
| 1003 | status = INSTALL_ERROR; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | if (status != INSTALL_SUCCESS) { |
| 1008 | ui->SetBackground(RecoveryUI::ERROR); |
| 1009 | ui->Print("Installation aborted.\n"); |
| 1010 | copy_logs(); |
| 1011 | } else if (!ui->IsTextVisible()) { |
| 1012 | return Device::NO_ACTION; // reboot if logs aren't visible |
| 1013 | } else { |
| 1014 | ui->Print("\nInstall from %s complete.\n", adb ? "ADB" : "SD card"); |
| 1015 | } |
| 1016 | } |
| 1017 | break; |
| 1018 | |
| 1019 | case Device::VIEW_RECOVERY_LOGS: |
| 1020 | choose_recovery_file(device); |
| 1021 | break; |
| 1022 | |
| 1023 | case Device::RUN_GRAPHICS_TEST: |
| 1024 | run_graphics_test(); |
| 1025 | break; |
| 1026 | |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 1027 | case Device::RUN_LOCALE_TEST: { |
| 1028 | ScreenRecoveryUI* screen_ui = static_cast<ScreenRecoveryUI*>(ui); |
| 1029 | screen_ui->CheckBackgroundTextImages(locale); |
| 1030 | break; |
| 1031 | } |
Tao Bao | 50dd532 | 2017-03-07 14:57:04 -0800 | [diff] [blame] | 1032 | case Device::MOUNT_SYSTEM: |
| 1033 | // For a system image built with the root directory (i.e. system_root_image == "true"), we |
| 1034 | // mount it to /system_root, and symlink /system to /system_root/system to make adb shell |
| 1035 | // work (the symlink is created through the build system). (Bug: 22855115) |
| 1036 | if (android::base::GetBoolProperty("ro.build.system_root_image", false)) { |
| 1037 | if (ensure_path_mounted_at("/", "/system_root") != -1) { |
| 1038 | ui->Print("Mounted /system.\n"); |
| 1039 | } |
| 1040 | } else { |
| 1041 | if (ensure_path_mounted("/system") != -1) { |
| 1042 | ui->Print("Mounted /system.\n"); |
| 1043 | } |
| 1044 | } |
| 1045 | break; |
| 1046 | } |
| 1047 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
Tao Bao | 99f0d9e | 2016-10-13 12:46:38 -0700 | [diff] [blame] | 1050 | static void print_property(const char* key, const char* name, void* /* cookie */) { |
| 1051 | printf("%s=%s\n", key, name); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1054 | static std::string load_locale_from_cache() { |
| 1055 | if (ensure_path_mounted(LOCALE_FILE) != 0) { |
| 1056 | LOG(ERROR) << "Can't mount " << LOCALE_FILE; |
| 1057 | return ""; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 1058 | } |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1059 | |
| 1060 | std::string content; |
| 1061 | if (!android::base::ReadFileToString(LOCALE_FILE, &content)) { |
| 1062 | PLOG(ERROR) << "Can't read " << LOCALE_FILE; |
| 1063 | return ""; |
| 1064 | } |
| 1065 | |
| 1066 | return android::base::Trim(content); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1069 | void ui_print(const char* format, ...) { |
| 1070 | std::string buffer; |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 1071 | va_list ap; |
| 1072 | va_start(ap, format); |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1073 | android::base::StringAppendV(&buffer, format, ap); |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 1074 | va_end(ap); |
| 1075 | |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1076 | if (ui != nullptr) { |
| 1077 | ui->Print("%s", buffer.c_str()); |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 1078 | } else { |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1079 | fputs(buffer.c_str(), stdout); |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
Tao Bao | f2ea6d7 | 2018-04-26 10:40:36 -0700 | [diff] [blame] | 1083 | static bool is_battery_ok(int* required_battery_level) { |
| 1084 | struct healthd_config healthd_config = { |
| 1085 | .batteryStatusPath = android::String8(android::String8::kEmptyString), |
| 1086 | .batteryHealthPath = android::String8(android::String8::kEmptyString), |
| 1087 | .batteryPresentPath = android::String8(android::String8::kEmptyString), |
| 1088 | .batteryCapacityPath = android::String8(android::String8::kEmptyString), |
| 1089 | .batteryVoltagePath = android::String8(android::String8::kEmptyString), |
| 1090 | .batteryTemperaturePath = android::String8(android::String8::kEmptyString), |
| 1091 | .batteryTechnologyPath = android::String8(android::String8::kEmptyString), |
| 1092 | .batteryCurrentNowPath = android::String8(android::String8::kEmptyString), |
| 1093 | .batteryCurrentAvgPath = android::String8(android::String8::kEmptyString), |
| 1094 | .batteryChargeCounterPath = android::String8(android::String8::kEmptyString), |
| 1095 | .batteryFullChargePath = android::String8(android::String8::kEmptyString), |
| 1096 | .batteryCycleCountPath = android::String8(android::String8::kEmptyString), |
| 1097 | .energyCounter = nullptr, |
| 1098 | .boot_min_cap = 0, |
| 1099 | .screen_on = nullptr |
| 1100 | }; |
| 1101 | healthd_board_init(&healthd_config); |
Yabin Cui | 99281df | 2016-02-17 12:21:52 -0800 | [diff] [blame] | 1102 | |
Tao Bao | f2ea6d7 | 2018-04-26 10:40:36 -0700 | [diff] [blame] | 1103 | android::BatteryMonitor monitor; |
| 1104 | monitor.init(&healthd_config); |
Yabin Cui | 99281df | 2016-02-17 12:21:52 -0800 | [diff] [blame] | 1105 | |
Tao Bao | f2ea6d7 | 2018-04-26 10:40:36 -0700 | [diff] [blame] | 1106 | static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10; |
| 1107 | int wait_second = 0; |
| 1108 | while (true) { |
| 1109 | int charge_status = monitor.getChargeStatus(); |
| 1110 | // Treat unknown status as charged. |
| 1111 | bool charged = (charge_status != android::BATTERY_STATUS_DISCHARGING && |
| 1112 | charge_status != android::BATTERY_STATUS_NOT_CHARGING); |
| 1113 | android::BatteryProperty capacity; |
| 1114 | android::status_t status = monitor.getProperty(android::BATTERY_PROP_CAPACITY, &capacity); |
| 1115 | ui_print("charge_status %d, charged %d, status %d, capacity %" PRId64 "\n", charge_status, |
| 1116 | charged, status, capacity.valueInt64); |
| 1117 | // At startup, the battery drivers in devices like N5X/N6P take some time to load |
| 1118 | // the battery profile. Before the load finishes, it reports value 50 as a fake |
| 1119 | // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected |
| 1120 | // to finish loading the battery profile earlier than 10 seconds after kernel startup. |
| 1121 | if (status == 0 && capacity.valueInt64 == 50) { |
| 1122 | if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) { |
| 1123 | sleep(1); |
| 1124 | wait_second++; |
| 1125 | continue; |
| 1126 | } |
Yabin Cui | 99281df | 2016-02-17 12:21:52 -0800 | [diff] [blame] | 1127 | } |
Tao Bao | f2ea6d7 | 2018-04-26 10:40:36 -0700 | [diff] [blame] | 1128 | // If we can't read battery percentage, it may be a device without battery. In this situation, |
| 1129 | // use 100 as a fake battery percentage. |
| 1130 | if (status != 0) { |
| 1131 | capacity.valueInt64 = 100; |
| 1132 | } |
| 1133 | |
| 1134 | // GmsCore enters recovery mode to install package when having enough battery percentage. |
| 1135 | // Normally, the threshold is 40% without charger and 20% with charger. So we should check |
| 1136 | // battery with a slightly lower limitation. |
| 1137 | static constexpr int BATTERY_OK_PERCENTAGE = 20; |
| 1138 | static constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15; |
| 1139 | *required_battery_level = charged ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE; |
| 1140 | return capacity.valueInt64 >= *required_battery_level; |
| 1141 | } |
Yabin Cui | 99281df | 2016-02-17 12:21:52 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1144 | // Set the retry count to |retry_count| in BCB. |
Tianjie Xu | 72449c9 | 2017-05-16 18:07:31 -0700 | [diff] [blame] | 1145 | static void set_retry_bootloader_message(int retry_count, const std::vector<std::string>& args) { |
| 1146 | std::vector<std::string> options; |
| 1147 | for (const auto& arg : args) { |
| 1148 | if (!android::base::StartsWith(arg, "--retry_count")) { |
| 1149 | options.push_back(arg); |
Tianjie Xu | 3c62b67 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 1150 | } |
Tianjie Xu | 72449c9 | 2017-05-16 18:07:31 -0700 | [diff] [blame] | 1151 | } |
Tianjie Xu | 3c62b67 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 1152 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1153 | // Update the retry counter in BCB. |
| 1154 | options.push_back(android::base::StringPrintf("--retry_count=%d", retry_count)); |
Tianjie Xu | 72449c9 | 2017-05-16 18:07:31 -0700 | [diff] [blame] | 1155 | std::string err; |
| 1156 | if (!update_bootloader_message(options, &err)) { |
| 1157 | LOG(ERROR) << err; |
| 1158 | } |
Tianjie Xu | 3c62b67 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
Tianjie Xu | 06e57ac | 2016-07-11 14:04:08 -0700 | [diff] [blame] | 1161 | static bool bootreason_in_blacklist() { |
Tao Bao | efc3559 | 2017-01-08 22:45:47 -0800 | [diff] [blame] | 1162 | std::string bootreason = android::base::GetProperty("ro.boot.bootreason", ""); |
| 1163 | if (!bootreason.empty()) { |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 1164 | // More bootreasons can be found in "system/core/bootstat/bootstat.cpp". |
| 1165 | static const std::vector<std::string> kBootreasonBlacklist{ |
| 1166 | "kernel_panic", |
| 1167 | "Panic", |
| 1168 | }; |
| 1169 | for (const auto& str : kBootreasonBlacklist) { |
| 1170 | if (android::base::EqualsIgnoreCase(str, bootreason)) return true; |
Tianjie Xu | 06e57ac | 2016-07-11 14:04:08 -0700 | [diff] [blame] | 1171 | } |
Tao Bao | efc3559 | 2017-01-08 22:45:47 -0800 | [diff] [blame] | 1172 | } |
| 1173 | return false; |
Tianjie Xu | 06e57ac | 2016-07-11 14:04:08 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 1176 | static void log_failure_code(ErrorCode code, const std::string& update_package) { |
| 1177 | std::vector<std::string> log_buffer = { |
| 1178 | update_package, |
| 1179 | "0", // install result |
| 1180 | "error: " + std::to_string(code), |
| 1181 | }; |
| 1182 | std::string log_content = android::base::Join(log_buffer, "\n"); |
| 1183 | const std::string& install_file = Paths::Get().temporary_install_file(); |
| 1184 | if (!android::base::WriteStringToFile(log_content, install_file)) { |
| 1185 | PLOG(ERROR) << "Failed to write " << install_file; |
| 1186 | } |
Tianjie Xu | 06e57ac | 2016-07-11 14:04:08 -0700 | [diff] [blame] | 1187 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 1188 | // Also write the info into last_log. |
| 1189 | LOG(INFO) << log_content; |
Tianjie Xu | 06e57ac | 2016-07-11 14:04:08 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
Tao Bao | 6d99d4b | 2018-04-25 16:47:04 -0700 | [diff] [blame] | 1192 | int start_recovery(int argc, char** argv) { |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1193 | time_t start = time(nullptr); |
| 1194 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1195 | printf("Starting recovery (pid %d) on %s", getpid(), ctime(&start)); |
| 1196 | |
| 1197 | load_volume_table(); |
| 1198 | has_cache = volume_for_mount_point(CACHE_ROOT) != nullptr; |
| 1199 | |
| 1200 | std::vector<std::string> args = get_args(argc, argv); |
| 1201 | std::vector<char*> args_to_parse(args.size()); |
| 1202 | std::transform(args.cbegin(), args.cend(), args_to_parse.begin(), |
| 1203 | [](const std::string& arg) { return const_cast<char*>(arg.c_str()); }); |
| 1204 | |
Tao Bao | f9f1734 | 2018-04-27 10:44:04 -0700 | [diff] [blame] | 1205 | static constexpr struct option OPTIONS[] = { |
| 1206 | { "just_exit", no_argument, nullptr, 'x' }, |
| 1207 | { "locale", required_argument, nullptr, 0 }, |
| 1208 | { "prompt_and_wipe_data", no_argument, nullptr, 0 }, |
| 1209 | { "reason", required_argument, nullptr, 0 }, |
| 1210 | { "retry_count", required_argument, nullptr, 0 }, |
| 1211 | { "security", no_argument, nullptr, 0 }, |
| 1212 | { "show_text", no_argument, nullptr, 't' }, |
| 1213 | { "shutdown_after", no_argument, nullptr, 0 }, |
| 1214 | { "sideload", no_argument, nullptr, 0 }, |
| 1215 | { "sideload_auto_reboot", no_argument, nullptr, 0 }, |
| 1216 | { "update_package", required_argument, nullptr, 0 }, |
| 1217 | { "wipe_ab", no_argument, nullptr, 0 }, |
| 1218 | { "wipe_cache", no_argument, nullptr, 0 }, |
| 1219 | { "wipe_data", no_argument, nullptr, 0 }, |
| 1220 | { "wipe_package_size", required_argument, nullptr, 0 }, |
| 1221 | { nullptr, 0, nullptr, 0 }, |
| 1222 | }; |
| 1223 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1224 | const char* update_package = nullptr; |
| 1225 | bool should_wipe_data = false; |
| 1226 | bool should_prompt_and_wipe_data = false; |
| 1227 | bool should_wipe_cache = false; |
| 1228 | bool should_wipe_ab = false; |
| 1229 | size_t wipe_package_size = 0; |
| 1230 | bool show_text = false; |
| 1231 | bool sideload = false; |
| 1232 | bool sideload_auto_reboot = false; |
| 1233 | bool just_exit = false; |
| 1234 | bool shutdown_after = false; |
| 1235 | int retry_count = 0; |
| 1236 | bool security_update = false; |
| 1237 | |
| 1238 | int arg; |
| 1239 | int option_index; |
| 1240 | while ((arg = getopt_long(args_to_parse.size(), args_to_parse.data(), "", OPTIONS, |
| 1241 | &option_index)) != -1) { |
| 1242 | switch (arg) { |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1243 | case 't': |
| 1244 | show_text = true; |
| 1245 | break; |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1246 | case 'x': |
| 1247 | just_exit = true; |
| 1248 | break; |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1249 | case 0: { |
| 1250 | std::string option = OPTIONS[option_index].name; |
Tao Bao | f9f1734 | 2018-04-27 10:44:04 -0700 | [diff] [blame] | 1251 | if (option == "locale") { |
| 1252 | locale = optarg; |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1253 | } else if (option == "prompt_and_wipe_data") { |
| 1254 | should_prompt_and_wipe_data = true; |
Tao Bao | f9f1734 | 2018-04-27 10:44:04 -0700 | [diff] [blame] | 1255 | } else if (option == "reason") { |
| 1256 | reason = optarg; |
| 1257 | } else if (option == "retry_count") { |
| 1258 | android::base::ParseInt(optarg, &retry_count, 0); |
| 1259 | } else if (option == "security") { |
| 1260 | security_update = true; |
| 1261 | } else if (option == "sideload") { |
| 1262 | sideload = true; |
| 1263 | } else if (option == "sideload_auto_reboot") { |
| 1264 | sideload = true; |
| 1265 | sideload_auto_reboot = true; |
| 1266 | } else if (option == "shutdown_after") { |
| 1267 | shutdown_after = true; |
| 1268 | } else if (option == "update_package") { |
| 1269 | update_package = optarg; |
| 1270 | } else if (option == "wipe_ab") { |
| 1271 | should_wipe_ab = true; |
| 1272 | } else if (option == "wipe_cache") { |
| 1273 | should_wipe_cache = true; |
| 1274 | } else if (option == "wipe_data") { |
| 1275 | should_wipe_data = true; |
| 1276 | } else if (option == "wipe_package_size") { |
| 1277 | android::base::ParseUint(optarg, &wipe_package_size); |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1278 | } |
| 1279 | break; |
| 1280 | } |
| 1281 | case '?': |
| 1282 | LOG(ERROR) << "Invalid command argument"; |
| 1283 | continue; |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 1284 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1285 | } |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 1286 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1287 | if (locale.empty()) { |
| 1288 | if (has_cache) { |
| 1289 | locale = load_locale_from_cache(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1290 | } |
| 1291 | |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1292 | if (locale.empty()) { |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 1293 | static constexpr const char* DEFAULT_LOCALE = "en-US"; |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1294 | locale = DEFAULT_LOCALE; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 1295 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1296 | } |
Tao Bao | ac9d94d | 2016-11-03 11:37:15 -0700 | [diff] [blame] | 1297 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1298 | printf("locale is [%s]\n", locale.c_str()); |
| 1299 | printf("stage is [%s]\n", stage.c_str()); |
| 1300 | printf("reason is [%s]\n", reason); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 1301 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1302 | Device* device = make_device(); |
| 1303 | if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { |
| 1304 | printf("Quiescent recovery mode.\n"); |
| 1305 | ui = new StubRecoveryUI(); |
| 1306 | } else { |
| 1307 | ui = device->GetUI(); |
| 1308 | |
| 1309 | if (!ui->Init(locale)) { |
| 1310 | printf("Failed to initialize UI, use stub UI instead.\n"); |
| 1311 | ui = new StubRecoveryUI(); |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | // Set background string to "installing security update" for security update, |
| 1316 | // otherwise set it to "installing system update". |
| 1317 | ui->SetSystemUpdateText(security_update); |
| 1318 | |
| 1319 | int st_cur, st_max; |
| 1320 | if (!stage.empty() && sscanf(stage.c_str(), "%d/%d", &st_cur, &st_max) == 2) { |
| 1321 | ui->SetStage(st_cur, st_max); |
| 1322 | } |
| 1323 | |
| 1324 | ui->SetBackground(RecoveryUI::NONE); |
| 1325 | if (show_text) ui->ShowText(true); |
| 1326 | |
| 1327 | sehandle = selinux_android_file_context_handle(); |
| 1328 | selinux_android_set_sehandle(sehandle); |
| 1329 | if (!sehandle) { |
| 1330 | ui->Print("Warning: No file_contexts\n"); |
| 1331 | } |
| 1332 | |
| 1333 | device->StartRecovery(); |
| 1334 | |
| 1335 | printf("Command:"); |
| 1336 | for (const auto& arg : args) { |
| 1337 | printf(" \"%s\"", arg.c_str()); |
| 1338 | } |
| 1339 | printf("\n\n"); |
| 1340 | |
| 1341 | property_list(print_property, nullptr); |
| 1342 | printf("\n"); |
| 1343 | |
| 1344 | ui->Print("Supported API: %d\n", kRecoveryApiVersion); |
| 1345 | |
| 1346 | int status = INSTALL_SUCCESS; |
| 1347 | |
| 1348 | if (update_package != nullptr) { |
| 1349 | // It's not entirely true that we will modify the flash. But we want |
| 1350 | // to log the update attempt since update_package is non-NULL. |
| 1351 | modified_flash = true; |
| 1352 | |
Tao Bao | f2ea6d7 | 2018-04-26 10:40:36 -0700 | [diff] [blame] | 1353 | int required_battery_level; |
| 1354 | if (retry_count == 0 && !is_battery_ok(&required_battery_level)) { |
| 1355 | ui->Print("battery capacity is not enough for installing package: %d%% needed\n", |
| 1356 | required_battery_level); |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1357 | // Log the error code to last_install when installation skips due to |
| 1358 | // low battery. |
| 1359 | log_failure_code(kLowBattery, update_package); |
| 1360 | status = INSTALL_SKIPPED; |
Tianjie Xu | a6f49bd | 2018-03-26 14:32:11 -0700 | [diff] [blame] | 1361 | } else if (retry_count == 0 && bootreason_in_blacklist()) { |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1362 | // Skip update-on-reboot when bootreason is kernel_panic or similar |
| 1363 | ui->Print("bootreason is in the blacklist; skip OTA installation\n"); |
| 1364 | log_failure_code(kBootreasonInBlacklist, update_package); |
| 1365 | status = INSTALL_SKIPPED; |
Dmitri Plotnikov | 8706a98 | 2017-04-18 08:28:26 -0700 | [diff] [blame] | 1366 | } else { |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1367 | // It's a fresh update. Initialize the retry_count in the BCB to 1; therefore we can later |
| 1368 | // identify the interrupted update due to unexpected reboots. |
| 1369 | if (retry_count == 0) { |
| 1370 | set_retry_bootloader_message(retry_count + 1, args); |
Tao Bao | 7022f33 | 2017-07-25 09:52:36 -0700 | [diff] [blame] | 1371 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1372 | |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 1373 | status = install_package(update_package, &should_wipe_cache, true, retry_count); |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1374 | if (status == INSTALL_SUCCESS && should_wipe_cache) { |
| 1375 | wipe_cache(false, device); |
| 1376 | } |
| 1377 | if (status != INSTALL_SUCCESS) { |
| 1378 | ui->Print("Installation aborted.\n"); |
Tao Bao | aac9d9f | 2018-04-29 23:38:59 -0700 | [diff] [blame] | 1379 | |
| 1380 | // When I/O error or bspatch/imgpatch error happens, reboot and retry installation |
| 1381 | // RETRY_LIMIT times before we abandon this OTA update. |
| 1382 | static constexpr int RETRY_LIMIT = 4; |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1383 | if (status == INSTALL_RETRY && retry_count < RETRY_LIMIT) { |
| 1384 | copy_logs(); |
| 1385 | retry_count += 1; |
| 1386 | set_retry_bootloader_message(retry_count, args); |
| 1387 | // Print retry count on screen. |
| 1388 | ui->Print("Retry attempt %d\n", retry_count); |
| 1389 | |
| 1390 | // Reboot and retry the update |
| 1391 | if (!reboot("reboot,recovery")) { |
| 1392 | ui->Print("Reboot failed\n"); |
| 1393 | } else { |
| 1394 | while (true) { |
| 1395 | pause(); |
| 1396 | } |
| 1397 | } |
Tianjie Xu | d9d1629 | 2017-04-20 18:08:21 -0700 | [diff] [blame] | 1398 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1399 | // If this is an eng or userdebug build, then automatically |
| 1400 | // turn the text display on if the script fails so the error |
| 1401 | // message is visible. |
| 1402 | if (is_ro_debuggable()) { |
| 1403 | ui->ShowText(true); |
Tao Bao | c679f93 | 2015-03-30 09:43:49 -0700 | [diff] [blame] | 1404 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1405 | } |
Doug Zongker | 8674a72 | 2010-09-15 11:08:23 -0700 | [diff] [blame] | 1406 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1407 | } else if (should_wipe_data) { |
| 1408 | if (!wipe_data(device)) { |
| 1409 | status = INSTALL_ERROR; |
Doug Zongker | b1d1263 | 2014-03-18 10:32:12 -0700 | [diff] [blame] | 1410 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1411 | } else if (should_prompt_and_wipe_data) { |
| 1412 | ui->ShowText(true); |
| 1413 | ui->SetBackground(RecoveryUI::ERROR); |
| 1414 | if (!prompt_and_wipe_data(device)) { |
| 1415 | status = INSTALL_ERROR; |
Tao Bao | 7523863 | 2015-05-27 14:46:17 -0700 | [diff] [blame] | 1416 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1417 | ui->ShowText(false); |
| 1418 | } else if (should_wipe_cache) { |
| 1419 | if (!wipe_cache(false, device)) { |
| 1420 | status = INSTALL_ERROR; |
| 1421 | } |
| 1422 | } else if (should_wipe_ab) { |
| 1423 | if (!wipe_ab_device(wipe_package_size)) { |
| 1424 | status = INSTALL_ERROR; |
| 1425 | } |
| 1426 | } else if (sideload) { |
| 1427 | // 'adb reboot sideload' acts the same as user presses key combinations |
| 1428 | // to enter the sideload mode. When 'sideload-auto-reboot' is used, text |
| 1429 | // display will NOT be turned on by default. And it will reboot after |
| 1430 | // sideload finishes even if there are errors. Unless one turns on the |
| 1431 | // text display during the installation. This is to enable automated |
| 1432 | // testing. |
| 1433 | if (!sideload_auto_reboot) { |
| 1434 | ui->ShowText(true); |
| 1435 | } |
Tao Bao | 641fa97 | 2018-04-25 18:59:40 -0700 | [diff] [blame] | 1436 | status = apply_from_adb(&should_wipe_cache); |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1437 | if (status == INSTALL_SUCCESS && should_wipe_cache) { |
| 1438 | if (!wipe_cache(false, device)) { |
| 1439 | status = INSTALL_ERROR; |
| 1440 | } |
| 1441 | } |
| 1442 | ui->Print("\nInstall from ADB complete (status: %d).\n", status); |
| 1443 | if (sideload_auto_reboot) { |
| 1444 | ui->Print("Rebooting automatically.\n"); |
| 1445 | } |
| 1446 | } else if (!just_exit) { |
| 1447 | // If this is an eng or userdebug build, automatically turn on the text display if no command |
| 1448 | // is specified. Note that this should be called before setting the background to avoid |
| 1449 | // flickering the background image. |
| 1450 | if (is_ro_debuggable()) { |
| 1451 | ui->ShowText(true); |
| 1452 | } |
| 1453 | status = INSTALL_NONE; // No command specified |
| 1454 | ui->SetBackground(RecoveryUI::NO_COMMAND); |
| 1455 | } |
| 1456 | |
| 1457 | if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) { |
| 1458 | ui->SetBackground(RecoveryUI::ERROR); |
| 1459 | if (!ui->IsTextVisible()) { |
| 1460 | sleep(5); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | Device::BuiltinAction after = shutdown_after ? Device::SHUTDOWN : Device::REBOOT; |
| 1465 | // 1. If the recovery menu is visible, prompt and wait for commands. |
| 1466 | // 2. If the state is INSTALL_NONE, wait for commands. (i.e. In user build, manually reboot into |
| 1467 | // recovery to sideload a package.) |
| 1468 | // 3. sideload_auto_reboot is an option only available in user-debug build, reboot the device |
| 1469 | // without waiting. |
| 1470 | // 4. In all other cases, reboot the device. Therefore, normal users will observe the device |
| 1471 | // reboot after it shows the "error" screen for 5s. |
| 1472 | if ((status == INSTALL_NONE && !sideload_auto_reboot) || ui->IsTextVisible()) { |
| 1473 | Device::BuiltinAction temp = prompt_and_wait(device, status); |
| 1474 | if (temp != Device::NO_ACTION) { |
| 1475 | after = temp; |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | // Save logs and clean up before rebooting or shutting down. |
| 1480 | finish_recovery(); |
| 1481 | |
| 1482 | switch (after) { |
| 1483 | case Device::SHUTDOWN: |
| 1484 | ui->Print("Shutting down...\n"); |
| 1485 | android::base::SetProperty(ANDROID_RB_PROPERTY, "shutdown,"); |
| 1486 | break; |
| 1487 | |
| 1488 | case Device::REBOOT_BOOTLOADER: |
| 1489 | ui->Print("Rebooting to bootloader...\n"); |
| 1490 | android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,bootloader"); |
| 1491 | break; |
| 1492 | |
| 1493 | default: |
| 1494 | ui->Print("Rebooting...\n"); |
| 1495 | reboot("reboot,"); |
| 1496 | break; |
| 1497 | } |
| 1498 | while (true) { |
| 1499 | pause(); |
| 1500 | } |
| 1501 | // Should be unreachable. |
| 1502 | return EXIT_SUCCESS; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1503 | } |