Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25900dd7 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

bootstat: add support for regex in aliasReasons and powerkeys

Add support for regex in aliasReasons for the alias member.  Use this
new feature to check powerkey|power_key|PowerKey for a single entry.

Test: boot_reason_test.sh
Bug: 63736262
Change-Id: Ia6add99b9e33f3197643dbaab88dde20aa726f90
parent 1e7d1c77
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -424,7 +424,7 @@ validate_reason() {
    reboot | reboot,?* ) ;;
    # Aliases and Heuristics
    *wdog* | *watchdog* )                   var="watchdog" ;;
    *powerkey* )              var="cold,powerkey" ;;
    *powerkey* | *power_key* | *PowerKey* ) var="cold,powerkey" ;;
    *panic* | *kernel_panic* )              var="kernel_panic" ;;
    *thermal* )                             var="shutdown,thermal" ;;
    *s3_wakeup* )                           var="warm,s3_wakeup" ;;
+10 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <ctime>
#include <map>
#include <memory>
#include <regex>
#include <string>
#include <utility>
#include <vector>
@@ -576,10 +577,16 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
    // A series of checks to take some officially unsupported reasons
    // reported by the bootloader and find some logical and canonical
    // sense.  In an ideal world, we would require those bootloaders
    // to behave and follow our standards.
    // to behave and follow our CTS standards.
    //
    // first member is the output
    // second member is an unanchored regex for an alias
    //
    // We match a needle on output. This helps keep the scale of the
    // following table smaller.
    static const std::vector<std::pair<const std::string, const std::string>> aliasReasons = {
        {"watchdog", "wdog"},
        {"cold,powerkey", "powerkey"},
        {"cold,powerkey", "powerkey|power_key|PowerKey"},
        {"kernel_panic", "panic"},
        {"shutdown,thermal", "thermal"},
        {"warm,s3_wakeup", "s3_wakeup"},
@@ -588,13 +595,12 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
        {"bootloader", ""},
    };

    // Either the primary or alias is found _somewhere_ in the reason string.
    for (auto& s : aliasReasons) {
      if (reason.find(s.first) != std::string::npos) {
        ret = s.first;
        break;
      }
      if (s.second.size() && (reason.find(s.second) != std::string::npos)) {
      if (s.second.size() && std::regex_search(reason, std::regex(s.second))) {
        ret = s.first;
        break;
      }