Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08de1891 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Prune files from /data/anr/ by number as well as age.

tombstoned prunes based on both age and number of files. Until we can
fully switch over to tombstoned, emulate that here too.

Bug: http://b/73140330
Test: ran tests
Change-Id: I824034019e91d541fc7b7ba49d152e1ceaf37621
parent 72fa61b3
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -5678,15 +5678,16 @@ public class ActivityManagerService extends IActivityManager.Stub
     * since it's the system_server that creates trace files for most ANRs.
     */
    private static void maybePruneOldTraces(File tracesDir) {
        final long now = System.currentTimeMillis();
        final File[] traceFiles = tracesDir.listFiles();
        final File[] files = tracesDir.listFiles();
        if (files == null) return;
        if (traceFiles != null) {
            for (File file : traceFiles) {
                if ((now - file.lastModified()) > DAY_IN_MILLIS)  {
                    if (!file.delete()) {
                        Slog.w(TAG, "Unable to prune stale trace file: " + file);
                    }
        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]);
                }
            }
        }