diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 19549666c..ac66b7f51 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -129,6 +129,7 @@ void SetProperty(const char* key, const char* val) { property_set(key, val); } +constexpr int32_t kEmptyBootReason = 0; constexpr int32_t kUnknownBootReason = 1; // A mapping from boot reason string, as read from the ro.boot.bootreason @@ -136,6 +137,7 @@ constexpr int32_t kUnknownBootReason = 1; // the boot_reason metric may refer to this mapping to discern the histogram // values. const std::map kBootReasonMap = { + {"empty", kEmptyBootReason}, {"unknown", kUnknownBootReason}, {"normal", 2}, {"recovery", 3}, @@ -216,6 +218,10 @@ int32_t BootReasonStrToEnum(const std::string& boot_reason) { return mapping->second; } + if (boot_reason.empty()) { + return kEmptyBootReason; + } + LOG(INFO) << "Unknown boot reason: " << boot_reason; return kUnknownBootReason; } @@ -747,8 +753,16 @@ void RecordBootComplete() { // property. void RecordBootReason() { const std::string reason(GetProperty(bootloader_reboot_reason_property)); - android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT, - android::metricslogger::FIELD_PLATFORM_REASON, reason); + + if (reason.empty()) { + // Log an empty boot reason value as '' to ensure the value is intentional + // (and not corruption anywhere else in the reporting pipeline). + android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT, + android::metricslogger::FIELD_PLATFORM_REASON, ""); + } else { + android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT, + android::metricslogger::FIELD_PLATFORM_REASON, reason); + } // Log the raw bootloader_boot_reason property value. int32_t boot_reason = BootReasonStrToEnum(reason);