Record tombstone proto file's timestamp into the dropbox

Avoid from creating duplicated entries in next reboot.

Bug: 215988435
Test: Manual - generate a tombstone, reboot, check dropbox dump.
Change-Id: I0c80c19c91f1b9a9e77ff2348ed9bef9248105d3
This commit is contained in:
Jing Ji
2022-02-02 23:52:25 -08:00
parent 128ebcdb54
commit 8bb2139def

View File

@@ -484,7 +484,9 @@ public class BootReceiver extends BroadcastReceiver {
HashMap<String, Long> timestamps = readTimestamps();
try {
if (proto) {
db.addFile(TAG_TOMBSTONE_PROTO, tombstone, 0);
if (recordFileTimestamp(tombstone, timestamps)) {
db.addFile(TAG_TOMBSTONE_PROTO, tombstone, 0);
}
} else {
final String headers = getBootHeadersToLogAndUpdate();
addFileToDropBox(db, timestamps, headers, tombstone.getPath(), LOG_SIZE,
@@ -526,16 +528,10 @@ public class BootReceiver extends BroadcastReceiver {
if (db == null || !db.isTagEnabled(tag)) return; // Logging disabled
File file = new File(filename);
long fileTime = file.lastModified();
if (fileTime <= 0) return; // File does not exist
if (timestamps.containsKey(filename) && timestamps.get(filename) == fileTime) {
return; // Already logged this particular file
if (!recordFileTimestamp(file, timestamps)) {
return;
}
timestamps.put(filename, fileTime);
String fileContents = FileUtils.readTextFile(file, maxSize, TAG_TRUNCATED);
String text = headers + fileContents + footers;
// Create an additional report for system server native crashes, with a special tag.
@@ -548,6 +544,19 @@ public class BootReceiver extends BroadcastReceiver {
addTextToDropBox(db, tag, text, filename, maxSize);
}
private static boolean recordFileTimestamp(File file, HashMap<String, Long> timestamps) {
final long fileTime = file.lastModified();
if (fileTime <= 0) return false; // File does not exist
final String filename = file.getPath();
if (timestamps.containsKey(filename) && timestamps.get(filename) == fileTime) {
return false; // Already logged this particular file
}
timestamps.put(filename, fileTime);
return true;
}
private static void addTextToDropBox(DropBoxManager db, String tag, String text,
String filename, int maxSize) {
Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")");