summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-07-13 02:51:29 +0200
committerandroid-build-merger <android-build-merger@google.com>2016-07-13 02:51:29 +0200
commitda873d77f311f53d6e9e11ef29948a454e4444c0 (patch)
tree867acb5b936a65898f5a1f24e529ddd6ed0cd75b
parentSupport landscape layouts. am: 6d089a955f (diff)
parentSkip update-on-boot for bootreason in blacklist (diff)
downloadandroid_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.tar
android_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.tar.gz
android_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.tar.bz2
android_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.tar.lz
android_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.tar.xz
android_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.tar.zst
android_bootable_recovery-da873d77f311f53d6e9e11ef29948a454e4444c0.zip
-rw-r--r--error_code.h3
-rw-r--r--recovery.cpp45
2 files changed, 38 insertions, 10 deletions
diff --git a/error_code.h b/error_code.h
index 259319ab4..fe38ba476 100644
--- a/error_code.h
+++ b/error_code.h
@@ -21,7 +21,8 @@ enum ErrorCode {
kNoError = -1,
kLowBattery = 20,
kZipVerificationFailure,
- kZipOpenFailure
+ kZipOpenFailure,
+ kBootreasonInBlacklist
};
enum CauseCode {
diff --git a/recovery.cpp b/recovery.cpp
index c0f5a386a..0c9c1472b 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -89,6 +89,12 @@ static const struct option OPTIONS[] = {
{ NULL, 0, NULL, 0 },
};
+// More bootreasons can be found in "system/core/bootstat/bootstat.cpp".
+static const std::vector<std::string> bootreason_blacklist {
+ "kernel_panic",
+ "Panic",
+};
+
static const char *CACHE_LOG_DIR = "/cache/recovery";
static const char *COMMAND_FILE = "/cache/recovery/command";
static const char *LOG_FILE = "/cache/recovery/log";
@@ -1390,6 +1396,30 @@ static void set_retry_bootloader_message(int retry_count, int argc, char** argv)
}
}
+static bool bootreason_in_blacklist() {
+ char bootreason[PROPERTY_VALUE_MAX];
+ if (property_get("ro.boot.bootreason", bootreason, nullptr) > 0) {
+ for (const auto& str : bootreason_blacklist) {
+ if (strcasecmp(str.c_str(), bootreason) == 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+static void log_failure_code(ErrorCode code, const char *update_package) {
+ FILE* install_log = fopen_path(TEMPORARY_INSTALL_FILE, "w");
+ if (install_log != nullptr) {
+ fprintf(install_log, "%s\n", update_package);
+ fprintf(install_log, "0\n");
+ fprintf(install_log, "error: %d\n", code);
+ fclose(install_log);
+ } else {
+ LOGE("failed to open last_install: %s\n", strerror(errno));
+ }
+}
+
static ssize_t logbasename(
log_id_t /* logId */,
char /* prio */,
@@ -1611,15 +1641,12 @@ int main(int argc, char **argv) {
BATTERY_OK_PERCENTAGE);
// Log the error code to last_install when installation skips due to
// low battery.
- FILE* install_log = fopen_path(LAST_INSTALL_FILE, "w");
- if (install_log != nullptr) {
- fprintf(install_log, "%s\n", update_package);
- fprintf(install_log, "0\n");
- fprintf(install_log, "error: %d\n", kLowBattery);
- fclose(install_log);
- } else {
- LOGE("failed to open last_install: %s\n", strerror(errno));
- }
+ log_failure_code(kLowBattery, update_package);
+ status = INSTALL_SKIPPED;
+ } else if (bootreason_in_blacklist()) {
+ // Skip update-on-reboot when bootreason is kernel_panic or similar
+ ui->Print("bootreason is in the blacklist; skip OTA installation\n");
+ log_failure_code(kBootreasonInBlacklist, update_package);
status = INSTALL_SKIPPED;
} else {
status = install_package(update_package, &should_wipe_cache,