Merge "Upload fsck logs to the dropbox when error found" into klp-dev

This commit is contained in:
Ken Sumrall
2013-09-23 20:07:10 +00:00
committed by Android (Google) Code Review

View File

@@ -127,6 +127,7 @@ public class BootReceiver extends BroadcastReceiver {
addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_threads",
-LOG_SIZE, "APANIC_THREADS");
addAuditErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_AUDIT");
addFsckErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_FSCK");
} else {
if (db != null) db.addText("SYSTEM_RESTART", headers);
}
@@ -203,4 +204,31 @@ public class BootReceiver extends BroadcastReceiver {
Slog.i(TAG, "Copied " + sb.toString().length() + " worth of audits to DropBox");
db.addText(tag, headers + sb.toString());
}
private static void addFsckErrorsToDropBox(DropBoxManager db, SharedPreferences prefs,
String headers, int maxSize, String tag) throws IOException {
boolean upload_needed = false;
if (db == null || !db.isTagEnabled(tag)) return; // Logging disabled
Slog.i(TAG, "Checking for fsck errors");
File file = new File("/dev/fscklogs/log");
long fileTime = file.lastModified();
if (fileTime <= 0) return; // File does not exist
String log = FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n");
StringBuilder sb = new StringBuilder();
for (String line : log.split("\n")) {
if (line.contains("FILE SYSTEM WAS MODIFIED")) {
upload_needed = true;
break;
}
}
if (upload_needed) {
addFileToDropBox(db, prefs, headers, "/dev/fscklogs/log", maxSize, tag);
}
// Remove the file so we don't re-upload if the runtime restarts.
file.delete();
}
}