summaryrefslogtreecommitdiffstats
path: root/recovery.cpp
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-07-11 23:04:08 +0200
committerTao Bao <tbao@google.com>2016-10-26 07:32:19 +0200
commit06e57acf35a4f85faa53b54120c1266f9c171cc6 (patch)
tree80d0fb9005425e89933b99f5d8a829271eb4a235 /recovery.cpp
parentMerge "tests: Generate testdata for 2nd arch." (diff)
downloadandroid_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.tar
android_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.tar.gz
android_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.tar.bz2
android_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.tar.lz
android_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.tar.xz
android_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.tar.zst
android_bootable_recovery-06e57acf35a4f85faa53b54120c1266f9c171cc6.zip
Diffstat (limited to '')
-rw-r--r--recovery.cpp52
1 files changed, 39 insertions, 13 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 683d101f5..4d1ad1df2 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -90,6 +90,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";
@@ -1395,6 +1401,33 @@ 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) {
+ std::vector<std::string> log_buffer = {
+ update_package,
+ "0", // install result
+ "error: " + std::to_string(code),
+ };
+ std::string log_content = android::base::Join(log_buffer, "\n");
+ if (!android::base::WriteStringToFile(log_content, TEMPORARY_INSTALL_FILE)) {
+ PLOG(ERROR) << "failed to write " << TEMPORARY_INSTALL_FILE;
+ }
+
+ // Also write the info into last_log.
+ LOG(INFO) << log_content;
+}
+
static ssize_t logbasename(
log_id_t /* logId */,
char /* prio */,
@@ -1620,19 +1653,12 @@ int main(int argc, char **argv) {
BATTERY_OK_PERCENTAGE);
// Log the error code to last_install when installation skips due to
// low battery.
- std::vector<std::string> log_buffer = {
- update_package,
- "0", // install result
- "error: " + std::to_string(kLowBattery),
- };
- std::string log_content = android::base::Join(log_buffer, "\n");
- if (!android::base::WriteStringToFile(log_content, LAST_INSTALL_FILE)) {
- PLOG(ERROR) << "failed to write " << LAST_INSTALL_FILE;
- }
-
- // Also write the info into last_log.
- LOG(INFO) << log_content;
-
+ 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,