Merge "Remove comments and code about ro.boot.slot"
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index e7f9c11..d4c45a2 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -291,6 +291,32 @@
return true;
}
+bool readPstoreConsole(std::string& console) {
+ if (android::base::ReadFileToString("/sys/fs/pstore/console-ramoops-0", &console)) {
+ return true;
+ }
+ return android::base::ReadFileToString("/sys/fs/pstore/console-ramoops", &console);
+}
+
+bool addKernelPanicSubReason(const std::string& console, std::string& ret) {
+ // Check for kernel panic types to refine information
+ if (console.rfind("SysRq : Trigger a crash") != std::string::npos) {
+ // Can not happen, except on userdebug, during testing/debugging.
+ ret = "kernel_panic,sysrq";
+ return true;
+ }
+ if (console.rfind("Unable to handle kernel NULL pointer dereference at virtual address") !=
+ std::string::npos) {
+ ret = "kernel_panic,NULL";
+ return true;
+ }
+ if (console.rfind("Kernel BUG at ") != std::string::npos) {
+ ret = "kernel_panic,BUG";
+ return true;
+ }
+ return false;
+}
+
// std::transform Helper callback functions:
// Converts a string value representing the reason the system booted to a
// string complying with Android system standard reason.
@@ -371,55 +397,51 @@
}
}
- // Check the other reason resources if the reason is still blunt.
- if (isBluntRebootReason(ret)) {
+ if (ret == "kernel_panic") {
// Check to see if last klog has some refinement hints.
std::string content;
- if (!android::base::ReadFileToString("/sys/fs/pstore/console-ramoops-0",
- &content)) {
- android::base::ReadFileToString("/sys/fs/pstore/console-ramoops",
- &content);
+ if (readPstoreConsole(content)) {
+ addKernelPanicSubReason(content, ret);
}
+ } else if (isBluntRebootReason(ret)) {
+ // Check the other available reason resources if the reason is still blunt.
- // The toybox reboot command used directly (unlikely)? But also
- // catches init's response to the Android's more controlled reboot command.
- if (content.rfind("reboot: Power down") != std::string::npos) {
- ret = "shutdown"; // Still too blunt, but more accurate.
- // ToDo: init should record the shutdown reason to kernel messages ala:
- // init: shutdown system with command 'last_reboot_reason'
- // so that if pstore has persistence we can get some details
- // that could be missing in last_reboot_reason_property.
- }
+ // Check to see if last klog has some refinement hints.
+ std::string content;
+ if (readPstoreConsole(content)) {
+ // The toybox reboot command used directly (unlikely)? But also
+ // catches init's response to Android's more controlled reboot command.
+ if (content.rfind("reboot: Power down") != std::string::npos) {
+ ret = "shutdown"; // Still too blunt, but more accurate.
+ // ToDo: init should record the shutdown reason to kernel messages ala:
+ // init: shutdown system with command 'last_reboot_reason'
+ // so that if pstore has persistence we can get some details
+ // that could be missing in last_reboot_reason_property.
+ }
- static const char cmd[] = "reboot: Restarting system with command '";
- size_t pos = content.rfind(cmd);
- if (pos != std::string::npos) {
- pos += strlen(cmd);
- std::string subReason(content.substr(pos));
- pos = subReason.find('\'');
- if (pos != std::string::npos) subReason.erase(pos);
- if (subReason != "") { // Will not land "reboot" as that is too blunt.
- if (isKernelRebootReason(subReason)) {
- ret = "reboot," + subReason; // User space can't talk kernel reasons.
- } else {
- ret = subReason;
+ static const char cmd[] = "reboot: Restarting system with command '";
+ size_t pos = content.rfind(cmd);
+ if (pos != std::string::npos) {
+ pos += strlen(cmd);
+ std::string subReason(content.substr(pos));
+ pos = subReason.find('\'');
+ if (pos != std::string::npos) subReason.erase(pos);
+ if (subReason != "") { // Will not land "reboot" as that is too blunt.
+ if (isKernelRebootReason(subReason)) {
+ ret = "reboot," + subReason; // User space can't talk kernel reasons.
+ } else {
+ ret = subReason;
+ }
}
}
- }
- // Check for kernel panics, but allowed to override reboot command.
- if (content.rfind("sysrq: SysRq : Trigger a crash") != std::string::npos) {
- // Can not happen, except on userdebug, during testing/debugging.
- ret = "kernel_panic,sysrq";
- } else if (content.rfind(
- "Unable to handle kernel NULL pointer dereference at virtual address")
- != std::string::npos) {
- ret = "kernel_panic,NULL";
- } else if (content.rfind("Kernel BUG at ") != std::string::npos) {
- ret = "kernel_panic,BUG";
- } else if ((content.rfind("Power held for ") != std::string::npos) ||
- (content.rfind("charger: [") != std::string::npos)) {
- ret = "cold";
+ // Check for kernel panics, allowed to override reboot command.
+ if (!addKernelPanicSubReason(content, ret) &&
+ // check for long-press power down
+ ((content.rfind("Power held for ") != std::string::npos) ||
+ (content.rfind("charger: [") != std::string::npos))) {
+ ret = "cold";
+ }
}
// The following battery test should migrate to a default system health HAL
@@ -433,7 +455,7 @@
// Really a hail-mary pass to find it in last klog content ...
static const int battery_dead_threshold = 2; // percent
static const char battery[] = "healthd: battery l=";
- pos = content.rfind(battery); // last one
+ size_t pos = content.rfind(battery); // last one
if (pos != std::string::npos) {
int level = atoi(content.substr(pos + strlen(battery)).c_str());
LOG(INFO) << "Battery level at shutdown " << level << "%";
@@ -497,7 +519,7 @@
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.
- pos = content.find(',');
+ size_t pos = content.find(',');
if (pos != std::string::npos) {
++pos;
std::string secondReason(content.substr(pos));
diff --git a/init/persistent_properties_test.cpp b/init/persistent_properties_test.cpp
index 875a4f3..872e9a1 100644
--- a/init/persistent_properties_test.cpp
+++ b/init/persistent_properties_test.cpp
@@ -52,7 +52,7 @@
entry.second == persistent_property_record.value();
});
ASSERT_TRUE(it != expected.end())
- << "Found unexpected proprety (" << persistent_property_record.name() << ", "
+ << "Found unexpected property (" << persistent_property_record.name() << ", "
<< persistent_property_record.value() << ")";
expected.erase(it);
}
diff --git a/libmetricslogger/Android.bp b/libmetricslogger/Android.bp
index 9b179d1..6549b8d 100644
--- a/libmetricslogger/Android.bp
+++ b/libmetricslogger/Android.bp
@@ -18,14 +18,6 @@
"-Wall",
"-Wextra",
"-Werror",
-
- // The following defines map logtag IDs as represented by:
- // frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags
- //
- // E.g., 524290 corresponds to sysui_count.
- "-DCOUNT_LOG_TAG=524290",
- "-DHISTOGRAM_LOG_TAG=524292",
- "-DMULTI_ACTION_LOG_TAG=524292",
],
}
diff --git a/libmetricslogger/metrics_logger.cpp b/libmetricslogger/metrics_logger.cpp
index a0dcf09..fdc4407 100644
--- a/libmetricslogger/metrics_logger.cpp
+++ b/libmetricslogger/metrics_logger.cpp
@@ -18,28 +18,37 @@
#include <cstdlib>
+#include <log/event_tag_map.h>
#include <log/log_event_list.h>
+namespace {
+
+EventTagMap* kEventTagMap = android_openEventTagMap(nullptr);
+const int kSysuiMultiActionTag = android_lookupEventTagNum(
+ kEventTagMap, "sysui_multi_action", "(content|4)", ANDROID_LOG_UNKNOWN);
+
+} // namespace
+
namespace android {
namespace metricslogger {
// Mirror com.android.internal.logging.MetricsLogger#histogram().
void LogHistogram(const std::string& event, int32_t data) {
- android_log_event_list log(HISTOGRAM_LOG_TAG);
+ android_log_event_list log(kSysuiMultiActionTag);
log << LOGBUILDER_CATEGORY << LOGBUILDER_HISTOGRAM << LOGBUILDER_NAME << event
<< LOGBUILDER_BUCKET << data << LOGBUILDER_VALUE << 1 << LOG_ID_EVENTS;
}
// Mirror com.android.internal.logging.MetricsLogger#count().
void LogCounter(const std::string& name, int32_t val) {
- android_log_event_list log(COUNT_LOG_TAG);
+ android_log_event_list log(kSysuiMultiActionTag);
log << LOGBUILDER_CATEGORY << LOGBUILDER_COUNTER << LOGBUILDER_NAME << name << LOGBUILDER_VALUE
<< val << LOG_ID_EVENTS;
}
// Mirror com.android.internal.logging.MetricsLogger#action().
void LogMultiAction(int32_t category, int32_t field, const std::string& value) {
- android_log_event_list log(MULTI_ACTION_LOG_TAG);
+ android_log_event_list log(kSysuiMultiActionTag);
log << LOGBUILDER_CATEGORY << category << LOGBUILDER_TYPE << TYPE_ACTION
<< field << value << LOG_ID_EVENTS;
}