Fix incorrect battery history merging logic to cause data losing am: 5e578ddd13

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14299195

Change-Id: I746e0ef1f7330d78f001c1b1ce92beac5464597b
This commit is contained in:
ykhung
2021-04-25 11:23:33 +00:00
committed by Automerger Merge Worker
2 changed files with 7 additions and 5 deletions

View File

@@ -203,10 +203,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
Collections.sort(batteryHistoryKeyList);
validateSlotTimestamp(batteryHistoryKeyList);
mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
final int elementSize = Math.min(batteryHistoryKeyList.size(), CHART_KEY_ARRAY_SIZE);
final int offset = CHART_KEY_ARRAY_SIZE - elementSize;
final int listSize = batteryHistoryKeyList.size();
final int elementSize = Math.min(listSize, CHART_KEY_ARRAY_SIZE);
for (int index = 0; index < elementSize; index++) {
mBatteryHistoryKeys[index + offset] = batteryHistoryKeyList.get(index);
mBatteryHistoryKeys[CHART_KEY_ARRAY_SIZE - index - 1] =
batteryHistoryKeyList.get(listSize - index - 1);
}
// Generates the battery history levels.
@@ -489,7 +490,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} else {
usageTimeSummary = buildUsageTimeInfo(totalUsageTimeInMs, false);
// Shows background usage time if it is larger than a minute.
if (backgroundUsageTimeInMs >= DateUtils.MINUTE_IN_MILLIS) {
if (backgroundUsageTimeInMs > 0) {
usageTimeSummary +=
"\n" + buildUsageTimeInfo(backgroundUsageTimeInMs, true);
}