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

Commit 78596ce7 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Prevent IndexOutOfBoundsException when trimming the battery history directory

Bug: 403795900
Test: atest PowerStatsTests
Flag: EXEMPT bugfix
Change-Id: I493ef77f418a5caa22512c8f1d1a2bcd4c770837
parent afeda299
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -505,7 +505,9 @@ public class BatteryHistoryDirectory implements BatteryStatsHistory.BatteryHisto
                for (int i = 0; i < mHistoryFiles.size(); i++) {
                    size += (int) mHistoryFiles.get(i).atomicFile.getBaseFile().length();
                }
                while (size > mMaxHistorySize) {
                // Trim until the directory size is within the limit or there is just one most
                // recent file left in the directory
                while (size > mMaxHistorySize && mHistoryFiles.size() > 1) {
                    BatteryHistoryFile oldest = mHistoryFiles.get(0);
                    int length = (int) oldest.atomicFile.getBaseFile().length();
                    oldest.atomicFile.delete();