Add last logcat data to incident report
Bug: 142721354
Test: adb sehll incident -p EXPLICIT 1109
Change-Id: Iaee370310e36998e161955e0f12d98ac8cd8eb90
diff --git a/cmds/incidentd/src/Section.cpp b/cmds/incidentd/src/Section.cpp
index f476fcf..0176f80 100644
--- a/cmds/incidentd/src/Section.cpp
+++ b/cmds/incidentd/src/Section.cpp
@@ -476,10 +476,27 @@
// initialization only once in Section.cpp.
map<log_id_t, log_time> LogSection::gLastLogsRetrieved;
-LogSection::LogSection(int id, log_id_t logID) : WorkerThreadSection(id), mLogID(logID) {
- name = "logcat ";
- name += android_log_id_to_name(logID);
- switch (logID) {
+LogSection::LogSection(int id, const char* logID, ...) : WorkerThreadSection(id), mLogMode(logModeBase) {
+ name = "logcat -b ";
+ name += logID;
+
+ va_list args;
+ va_start(args, logID);
+ mLogID = android_name_to_log_id(logID);
+ while(true) {
+ const char* arg = va_arg(args, const char*);
+ if (arg == NULL) {
+ break;
+ }
+ if (!strcmp(arg, "-L")) {
+ // Read from last logcat buffer
+ mLogMode = mLogMode | ANDROID_LOG_PSTORE;
+ }
+ name += " ";
+ name += arg;
+ }
+
+ switch (mLogID) {
case LOG_ID_EVENTS:
case LOG_ID_STATS:
case LOG_ID_SECURITY:
@@ -512,9 +529,8 @@
// Open log buffer and getting logs since last retrieved time if any.
unique_ptr<logger_list, void (*)(logger_list*)> loggers(
gLastLogsRetrieved.find(mLogID) == gLastLogsRetrieved.end()
- ? android_logger_list_alloc(ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, 0)
- : android_logger_list_alloc_time(ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK,
- gLastLogsRetrieved[mLogID], 0),
+ ? android_logger_list_alloc(mLogMode, 0, 0)
+ : android_logger_list_alloc_time(mLogMode, gLastLogsRetrieved[mLogID], 0),
android_logger_list_free);
if (android_logger_open(loggers.get(), mLogID) == NULL) {
diff --git a/cmds/incidentd/src/Section.h b/cmds/incidentd/src/Section.h
index c9b8056..fcf12f7 100644
--- a/cmds/incidentd/src/Section.h
+++ b/cmds/incidentd/src/Section.h
@@ -146,8 +146,11 @@
// global last log retrieved timestamp for each log_id_t.
static map<log_id_t, log_time> gLastLogsRetrieved;
+ // log mode: read only & non blocking.
+ const static int logModeBase = ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
+
public:
- LogSection(int id, log_id_t logID);
+ LogSection(int id, const char* logID, ...);
virtual ~LogSection();
virtual status_t BlockingCall(int pipeWriteFd) const;
@@ -155,6 +158,7 @@
private:
log_id_t mLogID;
bool mBinary;
+ int mLogMode;
};
/**
diff --git a/core/proto/android/os/incident.proto b/core/proto/android/os/incident.proto
index 7d0629ee..db65352 100644
--- a/core/proto/android/os/incident.proto
+++ b/core/proto/android/os/incident.proto
@@ -87,42 +87,80 @@
optional android.util.LogProto main_logs = 1101 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_MAIN"
+ (section).args = "main"
];
optional android.util.LogProto radio_logs = 1102 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_RADIO"
+ (section).args = "radio"
];
optional android.util.LogProto events_logs = 1103 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_EVENTS"
+ (section).args = "events"
];
optional android.util.LogProto system_logs = 1104 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_SYSTEM"
+ (section).args = "system"
];
optional android.util.LogProto crash_logs = 1105 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_CRASH"
+ (section).args = "crash"
];
optional android.util.LogProto stats_logs = 1106 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_STATS"
+ (section).args = "stats"
];
optional android.util.LogProto security_logs = 1107 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_SECURITY"
+ (section).args = "security"
];
optional android.util.LogProto kernel_logs = 1108 [
(section).type = SECTION_LOG,
- (section).args = "LOG_ID_KERNEL"
+ (section).args = "kernel"
+ ];
+
+ // Last logcat sections.
+ // Note that kernel logs is not persisted since it's contained in last kmsg.
+ optional android.util.LogProto last_main_logs = 1109 [
+ (section).type = SECTION_LOG,
+ (section).args = "main -L"
+ ];
+
+ optional android.util.LogProto last_radio_logs = 1110 [
+ (section).type = SECTION_LOG,
+ (section).args = "radio -L"
+ ];
+
+ optional android.util.LogProto last_events_logs = 1111 [
+ (section).type = SECTION_LOG,
+ (section).args = "events -L"
+ ];
+
+ optional android.util.LogProto last_system_logs = 1112 [
+ (section).type = SECTION_LOG,
+ (section).args = "system -L"
+ ];
+
+ optional android.util.LogProto last_crash_logs = 1113 [
+ (section).type = SECTION_LOG,
+ (section).args = "crash -L"
+ ];
+
+ optional android.util.LogProto last_stats_logs = 1114 [
+ (section).type = SECTION_LOG,
+ (section).args = "stats -L"
+ ];
+
+ // security logs is only available with "Device Owner" mode
+ optional android.util.LogProto last_security_logs = 1115 [
+ (section).type = SECTION_LOG,
+ (section).args = "security -L"
];
// Stack dumps
diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp
index 91f875e..ded4b91 100644
--- a/tools/incident_section_gen/main.cpp
+++ b/tools/incident_section_gen/main.cpp
@@ -436,7 +436,9 @@
printf(" NULL),\n");
break;
case SECTION_LOG:
- printf(" new LogSection(%d, %s),\n", field->number(), s.args().c_str());
+ printf(" new LogSection(%d, ", field->number());
+ splitAndPrint(s.args());
+ printf(" NULL),\n");
break;
case SECTION_GZIP:
printf(" new GZipSection(%d,", field->number());