init+bootstat: reduce last reboot reason to canonical alias

To make parsing easier for last reboot reason.  This also ensures that
last boot reason matches the content that is typically returned by the
bootloader or in turn landed in the canonical system boot reason.

Simplify parsing in bootstat.  Adjust and fix boot_reason_test.sh for
new reality.  Allow boot reason tests battery and kernel_panic to pass
if device does not support pstore (empty before and after the test).
If device somehow landed in fastboot mode while waiting for the
display, issue a fastboot reboot to move the test along.  Some cleanup
and standardization changes to the test script.

Test: system/core/bootstat/boot_reason_test.sh
Bug: 63736262
Change-Id: I97d5467c0b4a6d65df3525f1a2d0051db813d5ad
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index d26cf85..1954966 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -233,6 +233,7 @@
     "cold",
     "hard",
     "warm",
+    // super blunt
     "shutdown",    // Can not happen from ro.boot.bootreason
     "reboot",      // Default catch-all for anything unknown
     // clang-format on
@@ -543,19 +544,9 @@
       std::transform(content.begin(), content.end(), content.begin(), tounderline);
       std::transform(content.begin(), content.end(), content.begin(), toprintable);
 
-      // String is either "reboot,<reason>" or "shutdown,<reason>".
-      // We will set if default reasons, only override with detail if thermal.
-      if ((android::base::StartsWith(content, ret.c_str()) && (content[ret.length()] == ',')) ||
-          !isBluntRebootReason(content)) {
-        // Ok, we want it, let's squash it if secondReason is known.
-        size_t pos = content.find(',');
-        if (pos != std::string::npos) {
-          ++pos;
-          std::string secondReason(content.substr(pos));
-          ret = isKnownRebootReason(secondReason) ? secondReason : content;
-        } else {
-          ret = content;
-        }
+      // Anything in last is better than 'super-blunt' reboot or shutdown.
+      if ((ret == "") || (ret == "reboot") || (ret == "shutdown") || !isBluntRebootReason(content)) {
+        ret = content;
       }
     }
 
@@ -611,17 +602,11 @@
     boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
     LOG(INFO) << "Canonical boot reason: reboot,factory_reset";
     SetProperty(system_reboot_reason_property, "reboot,factory_reset");
-    if (GetProperty(bootloader_reboot_reason_property) == "") {
-      SetProperty(bootloader_reboot_reason_property, "reboot,factory_reset");
-    }
   } else if (build_date != record.second) {
     boot_complete_prefix = "ota_" + boot_complete_prefix;
     boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
     LOG(INFO) << "Canonical boot reason: reboot,ota";
     SetProperty(system_reboot_reason_property, "reboot,ota");
-    if (GetProperty(bootloader_reboot_reason_property) == "") {
-      SetProperty(bootloader_reboot_reason_property, "reboot,ota");
-    }
   }
 
   return boot_complete_prefix;