From 637d34ed71fa2ffa4b65752beac9ea81389d5a50 Mon Sep 17 00:00:00 2001 From: ykhung Date: Fri, 14 May 2021 15:17:37 +0800 Subject: [PATCH] Wrap generating battery history keys into another method Bug: 188123855 Test: make SettingsRoboTests Change-Id: I82a48e66ec4f7b4c0d9a6756799aa8d7a3a96848 --- .../BatteryChartPreferenceController.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java index 1b5c7795022..c435f8f5415 100644 --- a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java +++ b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java @@ -236,16 +236,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll mBatteryHistoryLevels = null; return; } - // Generates battery history timestamp slots. - final List batteryHistoryKeyList = - new ArrayList<>(batteryHistoryMap.keySet()); - Collections.sort(batteryHistoryKeyList); - mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE]; - for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) { - mBatteryHistoryKeys[index] = batteryHistoryKeyList.get(index); - } - - // Generates the battery history levels for chart graph. + mBatteryHistoryKeys = getBatteryHistoryKeys(batteryHistoryMap); mBatteryHistoryLevels = new int[CHART_LEVEL_ARRAY_SIZE]; for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) { final long timestamp = mBatteryHistoryKeys[index * 2]; @@ -273,7 +264,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll Log.d(TAG, String.format( "setBatteryHistoryMap() size=%d\nkeys=%s\nlevels=%s", - batteryHistoryKeyList.size(), + batteryHistoryMap.size(), utcToLocalTime(mBatteryHistoryKeys), Arrays.toString(mBatteryHistoryLevels))); } @@ -599,4 +590,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll } return true; } + + private static long[] getBatteryHistoryKeys( + final Map> batteryHistoryMap) { + final List batteryHistoryKeyList = + new ArrayList<>(batteryHistoryMap.keySet()); + Collections.sort(batteryHistoryKeyList); + final long[] batteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE]; + for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) { + batteryHistoryKeys[index] = batteryHistoryKeyList.get(index); + } + return batteryHistoryKeys; + } }