bootstat: move boot reason validation transformation policy into subroutine.
Allow for future policy adjustments. SideEffects: None Test: system/core/bootstat/boot_reason_test.sh Bug: 63736262 Change-Id: I571fb7dafc6b80c75d2809a3da3f9b96784cef06
This commit is contained in:
parent
72a8ea3d3c
commit
88d692c09e
1 changed files with 12 additions and 10 deletions
|
@ -353,10 +353,18 @@ bool addKernelPanicSubReason(const std::string& console, std::string& ret) {
|
|||
char tounderline(char c) {
|
||||
return ::isblank(c) ? '_' : c;
|
||||
}
|
||||
|
||||
char toprintable(char c) {
|
||||
return ::isprint(c) ? c : '?';
|
||||
}
|
||||
|
||||
// Cleanup boot_reason regarding acceptable character set
|
||||
void transformReason(std::string& reason) {
|
||||
std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower);
|
||||
std::transform(reason.begin(), reason.end(), reason.begin(), tounderline);
|
||||
std::transform(reason.begin(), reason.end(), reason.begin(), toprintable);
|
||||
}
|
||||
|
||||
const char system_reboot_reason_property[] = "sys.boot.reason";
|
||||
const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY;
|
||||
const char bootloader_reboot_reason_property[] = "ro.boot.bootreason";
|
||||
|
@ -370,10 +378,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
|
|||
// If sys.boot.reason == ro.boot.bootreason, let's re-evaluate
|
||||
if (reason == ret) ret = "";
|
||||
|
||||
// Cleanup boot_reason regarding acceptable character set
|
||||
std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower);
|
||||
std::transform(reason.begin(), reason.end(), reason.begin(), tounderline);
|
||||
std::transform(reason.begin(), reason.end(), reason.begin(), toprintable);
|
||||
transformReason(reason);
|
||||
|
||||
// Is the current system boot reason sys.boot.reason valid?
|
||||
if (!isKnownRebootReason(ret)) ret = "";
|
||||
|
@ -462,13 +467,13 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
|
|||
pos += strlen(cmd);
|
||||
std::string subReason(content.substr(pos, max_reason_length));
|
||||
for (pos = 0; pos < subReason.length(); ++pos) {
|
||||
char c = tounderline(subReason[pos]);
|
||||
char c = subReason[pos];
|
||||
if (!::isprint(c) || (c == '\'')) {
|
||||
subReason.erase(pos);
|
||||
break;
|
||||
}
|
||||
subReason[pos] = ::tolower(c);
|
||||
}
|
||||
transformReason(subReason);
|
||||
if (subReason != "") { // Will not land "reboot" as that is too blunt.
|
||||
if (isKernelRebootReason(subReason)) {
|
||||
ret = "reboot," + subReason; // User space can't talk kernel reasons.
|
||||
|
@ -565,10 +570,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
|
|||
// Content buffer no longer will have console data. Beware if more
|
||||
// checks added below, that depend on parsing console content.
|
||||
content = GetProperty(last_reboot_reason_property);
|
||||
// Cleanup last_boot_reason regarding acceptable character set
|
||||
std::transform(content.begin(), content.end(), content.begin(), ::tolower);
|
||||
std::transform(content.begin(), content.end(), content.begin(), tounderline);
|
||||
std::transform(content.begin(), content.end(), content.begin(), toprintable);
|
||||
transformReason(content);
|
||||
|
||||
// Anything in last is better than 'super-blunt' reboot or shutdown.
|
||||
if ((ret == "") || (ret == "reboot") || (ret == "shutdown") || !isBluntRebootReason(content)) {
|
||||
|
|
Loading…
Reference in a new issue