Merge "maybePruneOldTraces: bail if modification times change." am: 9144eaf12f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1712554

Change-Id: I9b2e87531f9167aa7b83fd2b30bc75722dee9257
This commit is contained in:
Elliott Hughes
2021-05-21 16:54:17 +00:00
committed by Automerger Merge Worker

View File

@@ -4060,13 +4060,19 @@ public class ActivityManagerService extends IActivityManager.Stub
final int max = SystemProperties.getInt("tombstoned.max_anr_count", 64);
final long now = System.currentTimeMillis();
Arrays.sort(files, Comparator.comparingLong(File::lastModified).reversed());
for (int i = 0; i < files.length; ++i) {
if (i > max || (now - files[i].lastModified()) > DAY_IN_MILLIS) {
if (!files[i].delete()) {
Slog.w(TAG, "Unable to prune stale trace file: " + files[i]);
try {
Arrays.sort(files, Comparator.comparingLong(File::lastModified).reversed());
for (int i = 0; i < files.length; ++i) {
if (i > max || (now - files[i].lastModified()) > DAY_IN_MILLIS) {
if (!files[i].delete()) {
Slog.w(TAG, "Unable to prune stale trace file: " + files[i]);
}
}
}
} catch (IllegalArgumentException e) {
// The modification times changed while we were sorting. Bail...
// https://issuetracker.google.com/169836837
Slog.w(TAG, "tombstone modification times changed while sorting; not pruning", e);
}
}