Merge "Add logging for kernel audit failures, including SELinux."
This commit is contained in:
committed by
Android (Google) Code Review
commit
044dca285f
@@ -126,6 +126,7 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
-LOG_SIZE, "APANIC_CONSOLE");
|
||||
addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_threads",
|
||||
-LOG_SIZE, "APANIC_THREADS");
|
||||
addAuditErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_AUDIT");
|
||||
} else {
|
||||
if (db != null) db.addText("SYSTEM_RESTART", headers);
|
||||
}
|
||||
@@ -174,4 +175,32 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")");
|
||||
db.addText(tag, headers + FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n"));
|
||||
}
|
||||
|
||||
private static void addAuditErrorsToDropBox(DropBoxManager db, SharedPreferences prefs,
|
||||
String headers, int maxSize, String tag) throws IOException {
|
||||
if (db == null || !db.isTagEnabled(tag)) return; // Logging disabled
|
||||
Slog.i(TAG, "Copying audit failures to DropBox");
|
||||
|
||||
File file = new File("/proc/last_kmsg");
|
||||
long fileTime = file.lastModified();
|
||||
if (fileTime <= 0) return; // File does not exist
|
||||
|
||||
if (prefs != null) {
|
||||
long lastTime = prefs.getLong(tag, 0);
|
||||
if (lastTime == fileTime) return; // Already logged this particular file
|
||||
// TODO: move all these SharedPreferences Editor commits
|
||||
// outside this function to the end of logBootEvents
|
||||
prefs.edit().putLong(tag, fileTime).apply();
|
||||
}
|
||||
|
||||
String log = FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String line : log.split("\n")) {
|
||||
if (line.contains("audit")) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
}
|
||||
Slog.i(TAG, "Copied " + sb.toString().length() + " worth of audits to DropBox");
|
||||
db.addText(tag, headers + sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user