From 431614cb6b2170fc715757dc6f964fdbb140ee7d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 18 Apr 2014 13:45:27 -0700 Subject: [PATCH] BootReceiver: add ro.boot.bootreason property to SYSTEM_LAST_KMSG Instead of requiring the kernel to join last_kmsg and the reboot reason together, allow both to be passed to userspace and have userspace combine them the way the log parsers want them. Existing devices with no ro.boot.bootreason property and kernel support for putting the reason in last_kmsg will continue to use the kernel's formatting. Bug: 13813279 Change-Id: I079b0107feb1533c6a54044ca6a114741127dfbc --- .../java/com/android/server/BootReceiver.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/BootReceiver.java b/services/core/java/com/android/server/BootReceiver.java index bce85cee338b9..724998570cb01 100644 --- a/services/core/java/com/android/server/BootReceiver.java +++ b/services/core/java/com/android/server/BootReceiver.java @@ -106,22 +106,33 @@ public class BootReceiver extends BroadcastReceiver { .append("Kernel: ") .append(FileUtils.readTextFile(new File("/proc/version"), 1024, "...\n")) .append("\n").toString(); + final String bootReason = SystemProperties.get("ro.boot.bootreason", null); String recovery = RecoverySystem.handleAftermath(); if (recovery != null && db != null) { db.addText("SYSTEM_RECOVERY_LOG", headers + recovery); } + String lastKmsgFooter = ""; + if (bootReason != null) { + lastKmsgFooter = new StringBuilder(512) + .append("\n") + .append("Boot info:\n") + .append("Last boot reason: ").append(bootReason).append("\n") + .toString(); + } + if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) { String now = Long.toString(System.currentTimeMillis()); SystemProperties.set("ro.runtime.firstboot", now); if (db != null) db.addText("SYSTEM_BOOT", headers); // Negative sizes mean to take the *tail* of the file (see FileUtils.readTextFile()) - addFileToDropBox(db, prefs, headers, "/proc/last_kmsg", - -LOG_SIZE, "SYSTEM_LAST_KMSG"); - addFileToDropBox(db, prefs, headers, "/sys/fs/pstore/console-ramoops", - -LOG_SIZE, "SYSTEM_LAST_KMSG"); + addFileWithFootersToDropBox(db, prefs, headers, lastKmsgFooter, + "/proc/last_kmsg", -LOG_SIZE, "SYSTEM_LAST_KMSG"); + addFileWithFootersToDropBox(db, prefs, headers, lastKmsgFooter, + "/sys/fs/pstore/console-ramoops", -LOG_SIZE, + "SYSTEM_LAST_KMSG"); addFileToDropBox(db, prefs, headers, "/cache/recovery/log", -LOG_SIZE, "SYSTEM_RECOVERY_LOG"); addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_console", @@ -161,6 +172,14 @@ public class BootReceiver extends BroadcastReceiver { private static void addFileToDropBox( DropBoxManager db, SharedPreferences prefs, String headers, String filename, int maxSize, String tag) throws IOException { + addFileWithFootersToDropBox(db, prefs, headers, "", filename, maxSize, + tag); + } + + private static void addFileWithFootersToDropBox( + DropBoxManager db, SharedPreferences prefs, + String headers, String footers, String filename, int maxSize, + String tag) throws IOException { if (db == null || !db.isTagEnabled(tag)) return; // Logging disabled File file = new File(filename); @@ -176,7 +195,7 @@ public class BootReceiver extends BroadcastReceiver { } Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")"); - db.addText(tag, headers + FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n")); + db.addText(tag, headers + FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n") + footers); } private static void addAuditErrorsToDropBox(DropBoxManager db, SharedPreferences prefs,