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:
@@ -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);
|
||||
}
|
||||
|
@@ -370,7 +370,8 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
pref, createBatteryDiffEntry(
|
||||
/*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
|
||||
/*backgroundUsageTimeInMs=*/ 200));
|
||||
assertThat(pref.getSummary()).isEqualTo("Total: 1 min");
|
||||
assertThat(pref.getSummary())
|
||||
.isEqualTo("Total: 1 min\nBackground: less than a min");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user