Store reason in case of userspace-reboot watchdog reboot

Test: adb reboot userspace
Bug: 148767783
Change-Id: I58cf103fd5ce47eadae334376109492d0cc1c1c6
This commit is contained in:
Nikita Ioffe 2020-02-19 16:21:11 +00:00
parent 529605bc9e
commit d0bc0b6f1e
1 changed files with 7 additions and 2 deletions

View File

@ -96,6 +96,11 @@ static std::vector<Service*> GetDebuggingServices(bool only_post_data) {
return ret; return ret;
} }
static void PersistRebootReason(const char* reason) {
SetProperty(LAST_REBOOT_REASON_PROPERTY, reason);
WriteStringToFile(reason, LAST_REBOOT_REASON_FILE);
}
// represents umount status during reboot / shutdown. // represents umount status during reboot / shutdown.
enum UmountStat { enum UmountStat {
/* umount succeeded. */ /* umount succeeded. */
@ -547,8 +552,7 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
reasons[1] == "hard" || reasons[1] == "warm")) { reasons[1] == "hard" || reasons[1] == "warm")) {
skip = strlen("reboot,"); skip = strlen("reboot,");
} }
SetProperty(LAST_REBOOT_REASON_PROPERTY, reason.c_str() + skip); PersistRebootReason(reason.c_str() + skip);
WriteStringToFile(reason.c_str() + skip, LAST_REBOOT_REASON_FILE);
sync(); sync();
bool is_thermal_shutdown = cmd == ANDROID_RB_THERMOFF; bool is_thermal_shutdown = cmd == ANDROID_RB_THERMOFF;
@ -829,6 +833,7 @@ static void UserspaceRebootWatchdogThread() {
if (!WaitForProperty("sys.boot_completed", "1", timeout)) { if (!WaitForProperty("sys.boot_completed", "1", timeout)) {
LOG(ERROR) << "Failed to boot in " << timeout.count() << "ms. Switching to full reboot"; LOG(ERROR) << "Failed to boot in " << timeout.count() << "ms. Switching to full reboot";
// In this case device is in a boot loop. Only way to recover is to do dirty reboot. // In this case device is in a boot loop. Only way to recover is to do dirty reboot.
PersistRebootReason("userspace_failed,watchdog_triggered");
RebootSystem(ANDROID_RB_RESTART2, "userspace_failed,watchdog_triggered"); RebootSystem(ANDROID_RB_RESTART2, "userspace_failed,watchdog_triggered");
} }
LOG(INFO) << "Device booted, stopping userspace reboot watchdog"; LOG(INFO) << "Device booted, stopping userspace reboot watchdog";