Adopt new battery history map with interpolation method
Bug: 184807417
Test: make SettingsRoboTests
Change-Id: I5c45a443d0a72df352d4bb707412328ad009f6d4
diff --git a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
index 4f19785..c4efef8 100644
--- a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
@@ -53,8 +53,10 @@
implements PreferenceControllerMixin, LifecycleObserver, OnPause, OnDestroy,
BatteryChartView.OnSelectListener, ExpandDividerPreference.OnExpandListener {
private static final String TAG = "BatteryChartPreferenceController";
- private static final int CHART_KEY_ARRAY_SIZE = 25;
+ /** Desired battery history size for timestamp slots. */
+ public static final int DESIRED_HISTORY_SIZE = 25;
private static final int CHART_LEVEL_ARRAY_SIZE = 13;
+ private static final int CHART_KEY_ARRAY_SIZE = DESIRED_HISTORY_SIZE;
private static final long VALID_USAGE_TIME_DURATION = DateUtils.HOUR_IN_MILLIS * 2;
private static final long VALID_DIFF_DURATION = DateUtils.MINUTE_IN_MILLIS * 3;
@@ -176,12 +178,12 @@
}
void setBatteryHistoryMap(
- final Map<Long, List<BatteryHistEntry>> batteryHistoryMap) {
+ final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
mHandler.post(() -> setBatteryHistoryMapInner(batteryHistoryMap));
}
private void setBatteryHistoryMapInner(
- final Map<Long, List<BatteryHistEntry>> batteryHistoryMap) {
+ final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
// Resets all battery history data relative variables.
if (batteryHistoryMap == null) {
mBatteryIndexedMap = null;
@@ -189,31 +191,32 @@
mBatteryHistoryLevels = null;
return;
}
- // Generates battery history keys.
+ // Generates battery history timestamp slots.
final List<Long> batteryHistoryKeyList =
- new ArrayList<Long>(batteryHistoryMap.keySet());
+ new ArrayList<>(batteryHistoryMap.keySet());
Collections.sort(batteryHistoryKeyList);
- validateSlotTimestamp(batteryHistoryKeyList);
mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
- final int listSize = batteryHistoryKeyList.size();
- final int elementSize = Math.min(listSize, CHART_KEY_ARRAY_SIZE);
- for (int index = 0; index < elementSize; index++) {
- mBatteryHistoryKeys[CHART_KEY_ARRAY_SIZE - index - 1] =
- batteryHistoryKeyList.get(listSize - index - 1);
+ for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
+ mBatteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
}
- // Generates the battery history levels.
+ // Generates the battery history levels for chart graph.
mBatteryHistoryLevels = new int[CHART_LEVEL_ARRAY_SIZE];
for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) {
- final Long timestamp = Long.valueOf(mBatteryHistoryKeys[index * 2]);
- final List<BatteryHistEntry> entryList = batteryHistoryMap.get(timestamp);
- if (entryList != null && !entryList.isEmpty()) {
- // All battery levels are the same in the same timestamp snapshot.
- mBatteryHistoryLevels[index] = entryList.get(0).mBatteryLevel;
- } else if (entryList != null && entryList.isEmpty()) {
- Log.e(TAG, "abnormal entry list in the timestamp:" +
- ConvertUtils.utcToLocalTime(timestamp));
+ final long timestamp = mBatteryHistoryKeys[index * 2];
+ final Map<String, BatteryHistEntry> entryMap = batteryHistoryMap.get(timestamp);
+ if (entryMap == null || entryMap.isEmpty()) {
+ Log.e(TAG, "abnormal entry list in the timestamp:"
+ + ConvertUtils.utcToLocalTime(timestamp));
+ continue;
}
+ // Averages the battery level in each time slot to avoid corner conditions.
+ float batteryLevelCounter = 0;
+ for (BatteryHistEntry entry : entryMap.values()) {
+ batteryLevelCounter += entry.mBatteryLevel;
+ }
+ mBatteryHistoryLevels[index] =
+ Math.round(batteryLevelCounter / entryMap.size());
}
// Generates indexed usage map for chart.
mBatteryIndexedMap =
@@ -532,25 +535,4 @@
}
return true;
}
-
- @VisibleForTesting
- static boolean validateSlotTimestamp(List<Long> batteryHistoryKeys) {
- // Whether the nearest two slot time diff is valid or not?
- final int size = batteryHistoryKeys.size();
- for (int index = 0; index < size - 1; index++) {
- final long currentTime = batteryHistoryKeys.get(index);
- final long nextTime = batteryHistoryKeys.get(index + 1);
- final long diffTime = Math.abs(
- DateUtils.HOUR_IN_MILLIS - Math.abs(currentTime - nextTime));
- if (currentTime == 0) {
- continue;
- } else if (diffTime > VALID_DIFF_DURATION) {
- Log.e(TAG, String.format("validateSlotTimestamp() %s > %s",
- ConvertUtils.utcToLocalTime(currentTime),
- ConvertUtils.utcToLocalTime(nextTime)));
- return false;
- }
- }
- return true;
- }
}
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryLoader.java b/src/com/android/settings/fuelgauge/BatteryHistoryLoader.java
index 97bdbd6..ddf3bf4 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryLoader.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryLoader.java
@@ -20,12 +20,11 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.utils.AsyncLoaderCompat;
-import java.util.List;
import java.util.Map;
/** Loader that can be used to load battery history information. */
public class BatteryHistoryLoader
- extends AsyncLoaderCompat<Map<Long, List<BatteryHistEntry>>> {
+ extends AsyncLoaderCompat<Map<Long, Map<String, BatteryHistEntry>>> {
private static final String TAG = "BatteryHistoryLoader";
private final Context mContext;
@@ -36,11 +35,11 @@
}
@Override
- protected void onDiscardResult(Map<Long, List<BatteryHistEntry>> result) {
+ protected void onDiscardResult(Map<Long, Map<String, BatteryHistEntry>> result) {
}
@Override
- public Map<Long, List<BatteryHistEntry>> loadInBackground() {
+ public Map<Long, Map<String, BatteryHistEntry>> loadInBackground() {
final PowerUsageFeatureProvider powerUsageFeatureProvider =
FeatureFactory.getFactory(mContext).getPowerUsageFeatureProvider(mContext);
return powerUsageFeatureProvider.getBatteryHistory(mContext);
diff --git a/src/com/android/settings/fuelgauge/ConvertUtils.java b/src/com/android/settings/fuelgauge/ConvertUtils.java
index f2c86f5..1f6600b 100644
--- a/src/com/android/settings/fuelgauge/ConvertUtils.java
+++ b/src/com/android/settings/fuelgauge/ConvertUtils.java
@@ -144,30 +144,9 @@
final Context context,
final int timeSlotSize,
final long[] batteryHistoryKeys,
- final Map<Long, List<BatteryHistEntry>> batteryHistoryMap,
+ final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap,
final boolean purgeLowPercentageData) {
final Map<Integer, List<BatteryDiffEntry>> resultMap = new HashMap<>();
- // Generates a temporary map to calculate diff usage data, which converts the inputted
- // List<BatteryDiffEntry> into Map<String, BatteryHistEntry> with the key comes from
- // the BatteryHistEntry.getKey() method.
- final Map<Long, Map<String, BatteryHistEntry>> newBatteryHistoryMap = new HashMap<>();
- for (int index = 0; index < batteryHistoryKeys.length; index++) {
- final Long timestamp = Long.valueOf(batteryHistoryKeys[index]);
- final List<BatteryHistEntry> entries = batteryHistoryMap.get(timestamp);
- if (entries == null || entries.isEmpty()) {
- continue;
- }
- final Map<String, BatteryHistEntry> slotBatteryHistDataMap = new HashMap<>();
- for (BatteryHistEntry entry : entries) {
- // Excludes auto-generated fake BatteryHistEntry data,
- // which is used to record battery level and status purpose only.
- if (!FAKE_PACKAGE_NAME.equals(entry.mPackageName)) {
- slotBatteryHistDataMap.put(entry.getKey(), entry);
- }
- }
- newBatteryHistoryMap.put(timestamp, slotBatteryHistDataMap);
- }
-
// Each time slot usage diff data =
// Math.abs(timestamp[i+2] data - timestamp[i+1] data) +
// Math.abs(timestamp[i+1] data - timestamp[i] data);
@@ -188,11 +167,11 @@
// Fetches BatteryHistEntry data from corresponding time slot.
final Map<String, BatteryHistEntry> currentBatteryHistMap =
- newBatteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
+ batteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
final Map<String, BatteryHistEntry> nextBatteryHistMap =
- newBatteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
+ batteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
final Map<String, BatteryHistEntry> nextTwoBatteryHistMap =
- newBatteryHistoryMap.getOrDefault(nextTwoTimestamp, EMPTY_BATTERY_MAP);
+ batteryHistoryMap.getOrDefault(nextTwoTimestamp, EMPTY_BATTERY_MAP);
// Collects all keys in these three time slot records as population.
final Set<String> allBatteryHistEntryKeys = new HashSet<>();
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index 98cbc8a..7c69618 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -52,7 +52,7 @@
@VisibleForTesting
BatteryHistoryPreference mHistPref;
@VisibleForTesting
- Map<Long, List<BatteryHistEntry>> mBatteryHistoryMap;
+ Map<Long, Map<String, BatteryHistEntry>> mBatteryHistoryMap;
@VisibleForTesting
final BatteryHistoryLoaderCallbacks mBatteryHistoryLoaderCallbacks =
new BatteryHistoryLoaderCallbacks();
@@ -210,25 +210,26 @@
};
private class BatteryHistoryLoaderCallbacks
- implements LoaderManager.LoaderCallbacks<Map<Long, List<BatteryHistEntry>>> {
+ implements LoaderManager.LoaderCallbacks<Map<Long, Map<String, BatteryHistEntry>>> {
private int mRefreshType;
@Override
@NonNull
- public Loader<Map<Long, List<BatteryHistEntry>>> onCreateLoader(int id, Bundle bundle) {
+ public Loader<Map<Long, Map<String, BatteryHistEntry>>> onCreateLoader(
+ int id, Bundle bundle) {
mRefreshType = bundle.getInt(KEY_REFRESH_TYPE);
return new BatteryHistoryLoader(getContext());
}
@Override
- public void onLoadFinished(Loader<Map<Long, List<BatteryHistEntry>>> loader,
- Map<Long, List<BatteryHistEntry>> batteryHistoryMap) {
+ public void onLoadFinished(Loader<Map<Long, Map<String, BatteryHistEntry>>> loader,
+ Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
mBatteryHistoryMap = batteryHistoryMap;
PowerUsageAdvanced.this.onLoadFinished(mRefreshType);
}
@Override
- public void onLoaderReset(Loader<Map<Long, List<BatteryHistEntry>>> loader) {
+ public void onLoaderReset(Loader<Map<Long, Map<String, BatteryHistEntry>>> loader) {
}
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 29487b9..7b97bdf 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -23,7 +23,6 @@
import com.android.internal.os.BatterySipper;
import com.android.settingslib.fuelgauge.Estimate;
-import java.util.List;
import java.util.Map;
/**
@@ -136,5 +135,5 @@
/**
* Returns battery history data with corresponding timestamp key.
*/
- Map<Long, List<BatteryHistEntry>> getBatteryHistory(Context context);
+ Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context);
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 1bbbba4..b9f225b 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -26,7 +26,6 @@
import com.android.internal.util.ArrayUtils;
import com.android.settingslib.fuelgauge.Estimate;
-import java.util.List;
import java.util.Map;
public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
@@ -160,7 +159,7 @@
}
@Override
- public Map<Long, List<BatteryHistEntry>> getBatteryHistory(Context context) {
+ public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
return null;
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
index 4e1d16c..a4f52dc 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
@@ -62,6 +62,8 @@
public final class BatteryChartPreferenceControllerTest {
private static final String PREF_KEY = "pref_key";
private static final String PREF_SUMMARY = "fake preference summary";
+ private static final int DESIRED_HISTORY_SIZE =
+ BatteryChartPreferenceController.DESIRED_HISTORY_SIZE;
@Mock private InstrumentedPreferenceFragment mFragment;
@Mock private SettingsActivity mSettingsActivity;
@@ -98,7 +100,7 @@
"fakeBatteryDiffEntryKey",
new BatteryEntry.NameAndIcon("fakeName", /*icon=*/ null, /*iconId=*/ 1));
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap(/*size=*/ 5));
+ createBatteryHistoryMap());
}
@Test
@@ -142,19 +144,19 @@
@Test
public void testSetBatteryHistoryMap_createExpectedKeysAndLevels() {
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap(/*size=*/ 5));
+ createBatteryHistoryMap());
// Verifies the created battery keys array.
- for (int index = 0; index < 25; index++) {
+ for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
// These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(index < 20 ? 0 : (index - 20 + 1));
+ .isEqualTo(index + 1);
}
// Verifies the created battery levels array.
for (int index = 0; index < 13; index++) {
assertThat(mBatteryChartPreferenceController.mBatteryHistoryLevels[index])
// These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(index < 10 ? 0 : (100 - (index - 10) * 2));
+ .isEqualTo(100 - index * 2);
}
assertThat(mBatteryChartPreferenceController.mBatteryIndexedMap).hasSize(13);
}
@@ -162,10 +164,10 @@
@Test
public void testSetBatteryHistoryMap_largeSize_createExpectedKeysAndLevels() {
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap(/*size=*/ 25));
+ createBatteryHistoryMap());
// Verifies the created battery keys array.
- for (int index = 0; index < 25; index++) {
+ for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
// These values is are calculated by hand from createBatteryHistoryMap().
.isEqualTo(index + 1);
@@ -214,7 +216,7 @@
mBatteryChartPreferenceController.mTrapezoidIndex =
BatteryChartView.SELECTED_INDEX_INVALID;
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap(/*size=*/ 25));
+ createBatteryHistoryMap());
assertThat(mBatteryChartPreferenceController.mTrapezoidIndex)
.isEqualTo(BatteryChartView.SELECTED_INDEX_ALL);
@@ -427,31 +429,6 @@
}
@Test
- public void testValidateSlotTimestamp_emptyContent_returnTrue() {
- assertThat(BatteryChartPreferenceController.validateSlotTimestamp(
- new ArrayList<Long>())).isTrue();
- }
-
- @Test
- public void testValidateSlotTimestamp_returnExpectedResult() {
- final ArrayList<Long> slotTimestampList = new ArrayList<Long>(
- Arrays.asList(
- Long.valueOf(0),
- Long.valueOf(DateUtils.HOUR_IN_MILLIS),
- Long.valueOf(DateUtils.HOUR_IN_MILLIS * 2 + DateUtils.MINUTE_IN_MILLIS),
- Long.valueOf(DateUtils.HOUR_IN_MILLIS * 3 + DateUtils.MINUTE_IN_MILLIS * 2)));
- // Verifies the testing data is correct before we added invalid data into it.
- assertThat(BatteryChartPreferenceController.validateSlotTimestamp(slotTimestampList))
- .isTrue();
-
- // Insert invalid timestamp into the list.
- slotTimestampList.add(
- Long.valueOf(DateUtils.HOUR_IN_MILLIS * 4 + DateUtils.MINUTE_IN_MILLIS * 6));
- assertThat(BatteryChartPreferenceController.validateSlotTimestamp(slotTimestampList))
- .isFalse();
- }
-
- @Test
public void testOnExpand_expandedIsTrue_addSystemEntriesToPreferenceGroup() {
doReturn(1).when(mAppListGroup).getPreferenceCount();
mBatteryChartPreferenceController.mSystemEntries.add(mBatteryDiffEntry);
@@ -582,13 +559,15 @@
.setTimestamps(any());
}
- private static Map<Long, List<BatteryHistEntry>> createBatteryHistoryMap(int size) {
- final Map<Long, List<BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
- for (int index = 0; index < size; index++) {
+ private static Map<Long, Map<String, BatteryHistEntry>> createBatteryHistoryMap() {
+ final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
+ for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
final ContentValues values = new ContentValues();
values.put("batteryLevel", Integer.valueOf(100 - index));
final BatteryHistEntry entry = new BatteryHistEntry(values);
- batteryHistoryMap.put(Long.valueOf(index + 1), Arrays.asList(entry));
+ final Map<String, BatteryHistEntry> entryMap = new HashMap<>();
+ entryMap.put("fake_entry_key" + index, entry);
+ batteryHistoryMap.put(Long.valueOf(index + 1), entryMap);
}
return batteryHistoryMap;
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java
index c3ab5e5..a0fd5fd 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java
@@ -23,7 +23,6 @@
import com.android.settings.testutils.FakeFeatureFactory;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.junit.Before;
@@ -51,7 +50,7 @@
@Test
public void testLoadIBackground_returnsMapFromPowerFeatureProvider() {
- final Map<Long, List<BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
+ final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
doReturn(batteryHistoryMap).when(mFeatureFactory.powerUsageFeatureProvider)
.getBatteryHistory(mContext);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
index 9539f0e..30df466 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
@@ -145,35 +145,45 @@
// Creates the fake testing data.
final int timeSlotSize = 2;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
- final Map<Long, List<BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
+ final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap =
+ new HashMap<>();
+ // Adds the index = 0 data.
+ Map<String, BatteryHistEntry> entryMap = new HashMap<>();
+ BatteryHistEntry entry = createBatteryHistEntry(
+ "package1", "label1", 5.0, 1L, 10L, 20L);
+ entryMap.put(entry.getKey(), entry);
+ batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[0]), entryMap);
+ // Adds the index = 1 data.
batteryHistoryMap.put(
- Long.valueOf(batteryHistoryKeys[0]),
- Arrays.asList(
- createBatteryHistEntry(
- "package1", "label1", 5.0, 1L, 10L, 20L)));
- batteryHistoryMap.put(
- Long.valueOf(batteryHistoryKeys[1]), new ArrayList<BatteryHistEntry>());
- batteryHistoryMap.put(
- Long.valueOf(batteryHistoryKeys[2]),
- Arrays.asList(
- createBatteryHistEntry(
- "package2", "label2", 10.0, 2L, 15L, 25L)));
- batteryHistoryMap.put(
- Long.valueOf(batteryHistoryKeys[3]),
- Arrays.asList(
- createBatteryHistEntry(
- "package2", "label2", 15.0, 2L, 25L, 35L),
- createBatteryHistEntry(
- "package3", "label3", 5.0, 3L, 5L, 5L)));
- batteryHistoryMap.put(
- Long.valueOf(batteryHistoryKeys[4]),
- Arrays.asList(
- createBatteryHistEntry(
- "package2", "label2", 30.0, 2L, 30L, 40L),
- createBatteryHistEntry(
- "package2", "label2", 75.0, 4L, 40L, 50L),
- createBatteryHistEntry(
- "package3", "label3", 5.0, 3L, 5L, 5L)));
+ Long.valueOf(batteryHistoryKeys[1]),
+ new HashMap<String, BatteryHistEntry>());
+ // Adds the index = 2 data.
+ entryMap = new HashMap<>();
+ entry = createBatteryHistEntry(
+ "package2", "label2", 10.0, 2L, 15L, 25L);
+ entryMap.put(entry.getKey(), entry);
+ batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[2]), entryMap);
+ // Adds the index = 3 data.
+ entryMap = new HashMap<>();
+ entry = createBatteryHistEntry(
+ "package2", "label2", 15.0, 2L, 25L, 35L);
+ entryMap.put(entry.getKey(), entry);
+ entry = createBatteryHistEntry(
+ "package3", "label3", 5.0, 3L, 5L, 5L);
+ entryMap.put(entry.getKey(), entry);
+ batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[3]), entryMap);
+ // Adds the index = 4 data.
+ entryMap = new HashMap<>();
+ entry = createBatteryHistEntry(
+ "package2", "label2", 30.0, 2L, 30L, 40L);
+ entryMap.put(entry.getKey(), entry);
+ entry = createBatteryHistEntry(
+ "package2", "label2", 75.0, 4L, 40L, 50L);
+ entryMap.put(entry.getKey(), entry);
+ entry = createBatteryHistEntry(
+ "package3", "label3", 5.0, 3L, 5L, 5L);
+ entryMap.put(entry.getKey(), entry);
+ batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[4]), entryMap);
final Map<Integer, List<BatteryDiffEntry>> resultMap =
ConvertUtils.getIndexedUsageMap(