Skip update-on-boot for bootreason in blacklist
Skip the OTA installation when bootreason is 'kernel_panic', 'Panic' etc. Change-Id: Ic1202492bffefa1a9d8d0e691b5af979285e552c Test: On angler, ota installation skips for one bootreason in the blacklist. Bug: 29978689
This commit is contained in:
+2
-1
@@ -21,7 +21,8 @@ enum ErrorCode {
|
|||||||
kNoError = -1,
|
kNoError = -1,
|
||||||
kLowBattery = 20,
|
kLowBattery = 20,
|
||||||
kZipVerificationFailure,
|
kZipVerificationFailure,
|
||||||
kZipOpenFailure
|
kZipOpenFailure,
|
||||||
|
kBootreasonInBlacklist
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CauseCode {
|
enum CauseCode {
|
||||||
|
|||||||
+36
-9
@@ -89,6 +89,12 @@ static const struct option OPTIONS[] = {
|
|||||||
{ NULL, 0, NULL, 0 },
|
{ 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 *CACHE_LOG_DIR = "/cache/recovery";
|
||||||
static const char *COMMAND_FILE = "/cache/recovery/command";
|
static const char *COMMAND_FILE = "/cache/recovery/command";
|
||||||
static const char *INTENT_FILE = "/cache/recovery/intent";
|
static const char *INTENT_FILE = "/cache/recovery/intent";
|
||||||
@@ -1405,6 +1411,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(
|
static ssize_t logbasename(
|
||||||
log_id_t /* logId */,
|
log_id_t /* logId */,
|
||||||
char /* prio */,
|
char /* prio */,
|
||||||
@@ -1628,15 +1658,12 @@ int main(int argc, char **argv) {
|
|||||||
BATTERY_OK_PERCENTAGE);
|
BATTERY_OK_PERCENTAGE);
|
||||||
// Log the error code to last_install when installation skips due to
|
// Log the error code to last_install when installation skips due to
|
||||||
// low battery.
|
// low battery.
|
||||||
FILE* install_log = fopen_path(LAST_INSTALL_FILE, "w");
|
log_failure_code(kLowBattery, update_package);
|
||||||
if (install_log != nullptr) {
|
status = INSTALL_SKIPPED;
|
||||||
fprintf(install_log, "%s\n", update_package);
|
} else if (bootreason_in_blacklist()) {
|
||||||
fprintf(install_log, "0\n");
|
// Skip update-on-reboot when bootreason is kernel_panic or similar
|
||||||
fprintf(install_log, "error: %d\n", kLowBattery);
|
ui->Print("bootreason is in the blacklist; skip OTA installation\n");
|
||||||
fclose(install_log);
|
log_failure_code(kBootreasonInBlacklist, update_package);
|
||||||
} else {
|
|
||||||
LOGE("failed to open last_install: %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
status = INSTALL_SKIPPED;
|
status = INSTALL_SKIPPED;
|
||||||
} else {
|
} else {
|
||||||
status = install_package(update_package, &should_wipe_cache,
|
status = install_package(update_package, &should_wipe_cache,
|
||||||
|
|||||||
Reference in New Issue
Block a user