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: Ia57002ef0ff4f085f89271eb7bf65b5e53199ff9
This commit is contained in:
ykhung
2021-04-25 11:25:20 +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); Collections.sort(batteryHistoryKeyList);
validateSlotTimestamp(batteryHistoryKeyList); validateSlotTimestamp(batteryHistoryKeyList);
mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE]; mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
final int elementSize = Math.min(batteryHistoryKeyList.size(), CHART_KEY_ARRAY_SIZE); final int listSize = batteryHistoryKeyList.size();
final int offset = CHART_KEY_ARRAY_SIZE - elementSize; final int elementSize = Math.min(listSize, CHART_KEY_ARRAY_SIZE);
for (int index = 0; index < elementSize; index++) { 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. // Generates the battery history levels.
@@ -489,7 +490,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} else { } else {
usageTimeSummary = buildUsageTimeInfo(totalUsageTimeInMs, false); usageTimeSummary = buildUsageTimeInfo(totalUsageTimeInMs, false);
// Shows background usage time if it is larger than a minute. // Shows background usage time if it is larger than a minute.
if (backgroundUsageTimeInMs >= DateUtils.MINUTE_IN_MILLIS) { if (backgroundUsageTimeInMs > 0) {
usageTimeSummary += usageTimeSummary +=
"\n" + buildUsageTimeInfo(backgroundUsageTimeInMs, true); "\n" + buildUsageTimeInfo(backgroundUsageTimeInMs, true);
} }

View File

@@ -370,7 +370,8 @@ public final class BatteryChartPreferenceControllerTest {
pref, createBatteryDiffEntry( pref, createBatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS, /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
/*backgroundUsageTimeInMs=*/ 200)); /*backgroundUsageTimeInMs=*/ 200));
assertThat(pref.getSummary()).isEqualTo("Total: 1 min"); assertThat(pref.getSummary())
.isEqualTo("Total: 1 min\nBackground: less than a min");
} }
@Test @Test