diff options
author | Tianjie Xu <xunchang@google.com> | 2016-03-08 00:47:14 +0100 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-03-08 00:47:14 +0100 |
commit | 94dc34148c117fd3cfb442a348a69dbbb676a5c5 (patch) | |
tree | c382122e7824b324082f03b5177e2997a7e29893 /recovery.cpp | |
parent | Merge "recovery: Handle devices without /cache partition." (diff) | |
parent | Reboot and retry on I/O errors (diff) | |
download | android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.tar android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.tar.gz android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.tar.bz2 android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.tar.lz android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.tar.xz android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.tar.zst android_bootable_recovery-94dc34148c117fd3cfb442a348a69dbbb676a5c5.zip |
Diffstat (limited to 'recovery.cpp')
-rw-r--r-- | recovery.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/recovery.cpp b/recovery.cpp index 9d6f51178..6781fa4b4 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -36,6 +36,7 @@ #include <adb.h> #include <android-base/file.h> +#include <android-base/parseint.h> #include <android-base/stringprintf.h> #include <cutils/android_reboot.h> #include <cutils/properties.h> @@ -60,6 +61,7 @@ struct selabel_handle *sehandle; static const struct option OPTIONS[] = { { "send_intent", required_argument, NULL, 'i' }, { "update_package", required_argument, NULL, 'u' }, + { "retry_count", required_argument, NULL, 'n' }, { "wipe_data", no_argument, NULL, 'w' }, { "wipe_cache", no_argument, NULL, 'c' }, { "show_text", no_argument, NULL, 't' }, @@ -86,6 +88,7 @@ static const char *TEMPORARY_INSTALL_FILE = "/tmp/last_install"; static const char *LAST_KMSG_FILE = "/cache/recovery/last_kmsg"; static const char *LAST_LOG_FILE = "/cache/recovery/last_log"; static const int KEEP_LOG_COUNT = 10; +static const int EIO_RETRY_COUNT = 2; static const int BATTERY_READ_TIMEOUT_IN_SEC = 10; // GmsCore enters recovery mode to install package when having enough battery // percentage. Normally, the threshold is 40% without charger and 20% with charger. @@ -1137,6 +1140,29 @@ static bool is_battery_ok() { } } +static void set_retry_bootloader_message(int retry_count, int argc, char** argv) { + struct bootloader_message boot {}; + strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); + strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); + + for (int i = 1; i < argc; ++i) { + if (strstr(argv[i], "retry_count") == nullptr) { + strlcat(boot.recovery, argv[i], sizeof(boot.recovery)); + strlcat(boot.recovery, "\n", sizeof(boot.recovery)); + } + } + + // Initialize counter to 1 if it's not in BCB, otherwise increment it by 1. + if (retry_count == 0) { + strlcat(boot.recovery, "--retry_count=1\n", sizeof(boot.recovery)); + } else { + char buffer[20]; + snprintf(buffer, sizeof(buffer), "--retry_count=%d\n", retry_count+1); + strlcat(boot.recovery, buffer, sizeof(boot.recovery)); + } + set_bootloader_message(&boot); +} + int main(int argc, char **argv) { // If this binary is started with the single argument "--adbd", // instead of being the normal recovery binary, it turns into kind @@ -1172,11 +1198,13 @@ int main(int argc, char **argv) { bool sideload_auto_reboot = false; bool just_exit = false; bool shutdown_after = false; + int retry_count = 0; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'i': send_intent = optarg; break; + case 'n': android::base::ParseInt(optarg, &retry_count, 0); break; case 'u': update_package = optarg; break; case 'w': should_wipe_data = true; break; case 'c': should_wipe_cache = true; break; @@ -1281,7 +1309,24 @@ int main(int argc, char **argv) { } if (status != INSTALL_SUCCESS) { ui->Print("Installation aborted.\n"); - + // When I/O error happens, reboot and retry installation EIO_RETRY_COUNT + // times before we abandon this OTA update. + if (status == INSTALL_RETRY && retry_count < EIO_RETRY_COUNT) { + copy_logs(); + set_retry_bootloader_message(retry_count, argc, argv); + // Print retry count on screen. + ui->Print("Retry attempt %d\n", retry_count); + + // Reboot and retry the update + int ret = property_set(ANDROID_RB_PROPERTY, "reboot,recovery"); + if (ret < 0) { + ui->Print("Reboot failed\n"); + } else { + while (true) { + pause(); + } + } + } // If this is an eng or userdebug build, then automatically // turn the text display on if the script fails so the error // message is visible. |