Fix incorrect battery history merging logic to cause data losing
Bug: 184807417 Test: make SettingsRoboTests Test: make SettingsGoogleRoboTests Change-Id: Ic26799f4d95b9f990e873ee26a42d6cc0c404659
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