Loading bootstat/bootstat.cpp +23 −17 Original line number Diff line number Diff line Loading @@ -468,7 +468,7 @@ class pstoreConsole { // If bit error match to needle, correct it. // Return true if any corrections were discovered and applied. bool correctForBer(std::string& reason, const std::string& needle) { bool correctForBitError(std::string& reason, const std::string& needle) { bool corrected = false; if (reason.length() < needle.length()) return corrected; const pstoreConsole console(reason); Loading @@ -486,6 +486,20 @@ bool correctForBer(std::string& reason, const std::string& needle) { return corrected; } // If bit error match to needle, correct it. // Return true if any corrections were discovered and applied. // Try again if we can replace underline with spaces. bool correctForBitErrorOrUnderline(std::string& reason, const std::string& needle) { bool corrected = correctForBitError(reason, needle); std::string _needle(needle); std::transform(_needle.begin(), _needle.end(), _needle.begin(), [](char c) { return (c == '_') ? ' ' : c; }); if (needle != _needle) { corrected |= correctForBitError(reason, _needle); } return corrected; } bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) { // Check for kernel panic types to refine information if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) || Loading @@ -510,22 +524,14 @@ bool addKernelPanicSubReason(const std::string& content, std::string& ret) { return addKernelPanicSubReason(pstoreConsole(content), ret); } // std::transform Helper callback functions: // Converts a string value representing the reason the system booted to a // string complying with Android system standard reason. 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); std::transform(reason.begin(), reason.end(), reason.begin(), [](char c) { return ::isblank(c) ? '_' : c; }); std::transform(reason.begin(), reason.end(), reason.begin(), [](char c) { return ::isprint(c) ? c : '?'; }); } const char system_reboot_reason_property[] = "sys.boot.reason"; Loading Loading @@ -632,14 +638,14 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { std::string subReason(content.substr(pos, max_reason_length)); // Correct against any known strings that Bit Error Match for (const auto& s : knownReasons) { correctForBer(subReason, s); correctForBitErrorOrUnderline(subReason, s); } for (const auto& m : kBootReasonMap) { if (m.first.length() <= strlen("cold")) continue; // too short? if (correctForBer(subReason, m.first + "'")) continue; if (correctForBitErrorOrUnderline(subReason, m.first + "'")) continue; if (m.first.length() <= strlen("reboot,cold")) continue; // short? if (!android::base::StartsWith(m.first, "reboot,")) continue; correctForBer(subReason, m.first.substr(strlen("reboot,")) + "'"); correctForBitErrorOrUnderline(subReason, m.first.substr(strlen("reboot,")) + "'"); } for (pos = 0; pos < subReason.length(); ++pos) { char c = subReason[pos]; Loading Loading @@ -687,7 +693,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { if (pos != std::string::npos) { digits = content.substr(pos + strlen(battery), strlen("100 ")); // correct common errors correctForBer(digits, "100 "); correctForBitError(digits, "100 "); if (digits[0] == '!') digits[0] = '1'; if (digits[1] == '!') digits[1] = '1'; } Loading Loading
bootstat/bootstat.cpp +23 −17 Original line number Diff line number Diff line Loading @@ -468,7 +468,7 @@ class pstoreConsole { // If bit error match to needle, correct it. // Return true if any corrections were discovered and applied. bool correctForBer(std::string& reason, const std::string& needle) { bool correctForBitError(std::string& reason, const std::string& needle) { bool corrected = false; if (reason.length() < needle.length()) return corrected; const pstoreConsole console(reason); Loading @@ -486,6 +486,20 @@ bool correctForBer(std::string& reason, const std::string& needle) { return corrected; } // If bit error match to needle, correct it. // Return true if any corrections were discovered and applied. // Try again if we can replace underline with spaces. bool correctForBitErrorOrUnderline(std::string& reason, const std::string& needle) { bool corrected = correctForBitError(reason, needle); std::string _needle(needle); std::transform(_needle.begin(), _needle.end(), _needle.begin(), [](char c) { return (c == '_') ? ' ' : c; }); if (needle != _needle) { corrected |= correctForBitError(reason, _needle); } return corrected; } bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) { // Check for kernel panic types to refine information if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) || Loading @@ -510,22 +524,14 @@ bool addKernelPanicSubReason(const std::string& content, std::string& ret) { return addKernelPanicSubReason(pstoreConsole(content), ret); } // std::transform Helper callback functions: // Converts a string value representing the reason the system booted to a // string complying with Android system standard reason. 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); std::transform(reason.begin(), reason.end(), reason.begin(), [](char c) { return ::isblank(c) ? '_' : c; }); std::transform(reason.begin(), reason.end(), reason.begin(), [](char c) { return ::isprint(c) ? c : '?'; }); } const char system_reboot_reason_property[] = "sys.boot.reason"; Loading Loading @@ -632,14 +638,14 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { std::string subReason(content.substr(pos, max_reason_length)); // Correct against any known strings that Bit Error Match for (const auto& s : knownReasons) { correctForBer(subReason, s); correctForBitErrorOrUnderline(subReason, s); } for (const auto& m : kBootReasonMap) { if (m.first.length() <= strlen("cold")) continue; // too short? if (correctForBer(subReason, m.first + "'")) continue; if (correctForBitErrorOrUnderline(subReason, m.first + "'")) continue; if (m.first.length() <= strlen("reboot,cold")) continue; // short? if (!android::base::StartsWith(m.first, "reboot,")) continue; correctForBer(subReason, m.first.substr(strlen("reboot,")) + "'"); correctForBitErrorOrUnderline(subReason, m.first.substr(strlen("reboot,")) + "'"); } for (pos = 0; pos < subReason.length(); ++pos) { char c = subReason[pos]; Loading Loading @@ -687,7 +693,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { if (pos != std::string::npos) { digits = content.substr(pos + strlen(battery), strlen("100 ")); // correct common errors correctForBer(digits, "100 "); correctForBitError(digits, "100 "); if (digits[0] == '!') digits[0] = '1'; if (digits[1] == '!') digits[1] = '1'; } Loading