Port battery usage bug fixing cls from master to tm-qpr-dev

This cl is a merge of the following 5 cls:
ag/19674112	Fix b/242989581: The two battery charts have the same label
ag/19667114	Support data logging for battery usage new chart view
ag/19636171	Support data logging for battery usage new chart view
ag/19682758	Resolve insufficient contrast for system component icons
ag/19697763	Add fade in animation for battery usage chart group

Bug: 242989581
Bug: 242810430
Bug: 242989982
Test: presubmit
Change-Id: I39cd0f88ce62a280a966750082a40f8a537b9616
Merged-In: Ice30508bc20b5de631efee0db0160fe6ad710dbb
This commit is contained in:
Zaiyue Xue
2022-08-19 14:29:00 +08:00
parent bf23a06eac
commit 2a57f5de8d
18 changed files with 186 additions and 62 deletions

View File

@@ -1,5 +1,5 @@
<!--
Copyright (C) 2019 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,11 +19,11 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path
android:fillColor="#000000"
android:fillColor="@android:color/white"
android:pathData="M20,7v13H7L20,7 M22,2L2,22h20V2L22,2z" />
<path
android:fillColor="#000000"
android:fillColor="@android:color/white"
android:pathData="M 11 13 L 2 22 L 11 22 Z" />
</vector>

View File

@@ -1,5 +1,5 @@
<!--
Copyright (C) 2019 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,8 +19,8 @@
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path
android:fillColor="#000000"
android:fillColor="@android:color/white"
android:pathData="M6,18c0,0.55 0.45,1 1,1h1v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L11,19h2v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L16,19h1c0.55,0 1,-0.45 1,-1L18,8L6,8v10zM3.5,8C2.67,8 2,8.67 2,9.5v7c0,0.83 0.67,1.5 1.5,1.5S5,17.33 5,16.5v-7C5,8.67 4.33,8 3.5,8zM20.5,8c-0.83,0 -1.5,0.67 -1.5,1.5v7c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5v-7c0,-0.83 -0.67,-1.5 -1.5,-1.5zM15.53,2.16l1.3,-1.3c0.2,-0.2 0.2,-0.51 0,-0.71 -0.2,-0.2 -0.51,-0.2 -0.71,0l-1.48,1.48C13.85,1.23 12.95,1 12,1c-0.96,0 -1.86,0.23 -2.66,0.63L7.85,0.15c-0.2,-0.2 -0.51,-0.2 -0.71,0 -0.2,0.2 -0.2,0.51 0,0.71l1.31,1.31C6.97,3.26 6,5.01 6,7h12c0,-1.99 -0.97,-3.75 -2.47,-4.84zM10,5L9,5L9,4h1v1zM15,5h-1L14,4h1v1z"/>
</vector>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,16 +19,16 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path
android:fillColor="#000000"
android:fillColor="@android:color/white"
android:pathData="M17,1.01L7,1C5.9,1,5,1.9,5,3v18c0,1.1,0.9,2,2,2h10c1.1,0,2-0.9,2-2V3C19,1.9,18.1,1.01,17,1.01z M17,21H7l0-1h10V21z M17,18H7V6h10V18z M17,4H7V3h10V4z"/>
<path
android:fillColor="#000000"
android:fillColor="@android:color/white"
android:pathData="M 8 10 H 16 V 11.5 H 8 V 10 Z"/>
<path
android:fillColor="#000000"
android:fillColor="@android:color/white"
android:pathData="M 9 13 H 15 V 14.5 H 9 V 13 Z"/>
<path
android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z"/>

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="@color/battery_usage_system_icon_color">
<path
android:fillColor="@android:color/white"
android:pathData="M17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88z"/>
</vector>

View File

@@ -1,5 +1,5 @@
<!--
Copyright (C) 2015 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -21,9 +21,9 @@
android:viewportWidth="48"
android:viewportHeight="48"
android:autoMirrored="true"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path android:fillColor="#000000"
<path android:fillColor="@android:color/white"
android:pathData="M18.8 21l9.53-16.51C26.94 4.18 25.49 4 24 4c-4.8 0-9.19 1.69-12.64
4.51l7.33 12.69.11-.2zm24.28-3c-1.84-5.85-6.3-10.52-11.99-12.68L23.77
18h19.31zm.52 2H28.62l.58 1 9.53 16.5C41.99 33.94 44 29.21 44

View File

@@ -1,5 +1,5 @@
<!--
Copyright (C) 2016 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path
android:fillColor="#FFFFFFFF"
android:fillColor="@android:color/white"
android:pathData="M20,8.69V4h-4.69L12,0.69L8.69,4H4v4.69L0.69,12L4,15.31V20h4.69L12,23.31L15.31,20H20v-4.69L23.31,12L20,8.69zM18,14.48V18h-3.52L12,20.48L9.52,18H6v-3.52L3.52,12L6,9.52V6h3.52L12,3.52L14.48,6H18v3.52L20.48,12L18,14.48zM12,17c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5V17z"/>
</vector>

View File

@@ -1,5 +1,5 @@
<!--
Copyright (C) 2019 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path
android:pathData="M14,48h4v-4h-4v4zM22,48h4v-4h-4v4zM26,4h-4v20h4L26,4zM33.13,8.87l-2.89,2.89C33.69,13.87 36,17.66 36,22c0,6.63 -5.37,12 -12,12s-12,-5.37 -12,-12c0,-4.34 2.31,-8.13 5.76,-10.24l-2.89,-2.89C10.72,11.76 8,16.56 8,22c0,8.84 7.16,16 16,16s16,-7.16 16,-16c0,-5.44 -2.72,-10.24 -6.87,-13.13zM30,48h4v-4h-4v4z"
android:fillColor="#000000"/>
android:fillColor="@android:color/white"
android:pathData="M14,48h4v-4h-4v4zM22,48h4v-4h-4v4zM26,4h-4v20h4L26,4zM33.13,8.87l-2.89,2.89C33.69,13.87 36,17.66 36,22c0,6.63 -5.37,12 -12,12s-12,-5.37 -12,-12c0,-4.34 2.31,-8.13 5.76,-10.24l-2.89,-2.89C10.72,11.76 8,16.56 8,22c0,8.84 7.16,16 16,16s16,-7.16 16,-16c0,-5.44 -2.72,-10.24 -6.87,-13.13zM30,48h4v-4h-4v4z"/>
</vector>

View File

@@ -1,5 +1,5 @@
<!--
Copyright (C) 2019 The Android Open Source Project
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?android:attr/colorControlNormal">
android:tint="@color/battery_usage_system_icon_color">
<path
android:pathData="M40,31c-2.49,0 -4.89,-0.4 -7.14,-1.14 -0.69,-0.22 -1.48,-0.06 -2.03,0.49l-4.4,4.41c-5.67,-2.88 -10.29,-7.51 -13.18,-13.17l4.4,-4.41c0.55,-0.55 0.71,-1.34 0.49,-2.03C17.4,12.9 17,10.49 17,8c0,-1.11 -0.89,-2 -2,-2L8,6c-1.11,0 -2,0.89 -2,2 0,18.78 15.22,34 34,34 1.11,0 2,-0.89 2,-2v-7c0,-1.11 -0.89,-2 -2,-2zM38,24h4c0,-9.94 -8.06,-18 -18,-18v4c7.73,0 14,6.27 14,14zM30,24h4c0,-5.52 -4.48,-10 -10,-10v4c3.31,0 6,2.69 6,6z"
android:fillColor="#000000"/>
android:fillColor="@android:color/white"
android:pathData="M40,31c-2.49,0 -4.89,-0.4 -7.14,-1.14 -0.69,-0.22 -1.48,-0.06 -2.03,0.49l-4.4,4.41c-5.67,-2.88 -10.29,-7.51 -13.18,-13.17l4.4,-4.41c0.55,-0.55 0.71,-1.34 0.49,-2.03C17.4,12.9 17,10.49 17,8c0,-1.11 -0.89,-2 -2,-2L8,6c-1.11,0 -2,0.89 -2,2 0,18.78 15.22,34 34,34 1.11,0 2,-0.89 2,-2v-7c0,-1.11 -0.89,-2 -2,-2zM38,24h4c0,-9.94 -8.06,-18 -18,-18v4c7.73,0 14,6.27 14,14zM30,24h4c0,-5.52 -4.48,-10 -10,-10v4c3.31,0 6,2.69 6,6z"/>
</vector>

View File

@@ -0,0 +1,30 @@
<!--
Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="@color/battery_usage_system_icon_color">
<path
android:pathData="M1.003,9L3.003,11C7.973,6.03 16.033,6.03 21.003,11L23.003,9C16.933,2.93 7.083,2.93 1.003,9ZM9.003,17L12.003,20L15.003,17C13.353,15.34 10.663,15.34 9.003,17ZM7.005,15L5.005,13C8.875,9.14 15.145,9.14 19.005,13L17.005,15C14.245,12.241 9.765,12.241 7.005,15Z"
android:fillType="evenOdd"
android:fillColor="@android:color/white"/>
<path
android:pathData="M0,0H24V24H0V0ZM0,0H24V24H0V0Z"
android:fillType="evenOdd"
android:fillColor="@android:color/white"/>
</vector>

View File

@@ -31,13 +31,19 @@
android:textColor="?android:attr/textColorSecondary"
android:text="@string/battery_usage_chart_graph_hint_last_full_charge" />
<LinearLayout
android:id="@+id/battery_chart_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:alpha="0">
<com.android.settings.fuelgauge.batteryusage.BatteryChartView
android:id="@+id/daily_battery_chart"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_marginBottom="16dp"
android:visibility="gone"
android:contentDescription="@string/battery_usage_chart"
android:contentDescription="@string/daily_battery_usage_chart"
android:textAppearance="?android:attr/textAppearanceSmall"
settings:textColor="?android:attr/textColorSecondary" />
@@ -47,9 +53,11 @@
android:layout_height="170dp"
android:layout_marginBottom="16dp"
android:visibility="visible"
android:contentDescription="@string/battery_usage_chart"
android:contentDescription="@string/hourly_battery_usage_chart"
android:textAppearance="?android:attr/textAppearanceSmall"
settings:textColor="?android:attr/textColorSecondary" />
</LinearLayout>
<!-- Use non-scalable text size from text_size_small_material -->
<TextView
android:id="@+id/companion_text"

View File

@@ -52,5 +52,8 @@
<!-- Material inverse ripple color, useful for inverted backgrounds. -->
<color name="ripple_material_inverse">@*android:color/ripple_material_light</color>
<!-- Icon tint color for battery usage system icon -->
<color name="battery_usage_system_icon_color">@android:color/white</color>
</resources>

View File

@@ -209,4 +209,7 @@
<!-- Background for multiple user settings page avatars -->
<color name="user_avatar_color_bg">?androidprv:attr/colorSurface</color>
<!-- Icon tint color for battery usage system icon -->
<color name="battery_usage_system_icon_color">?android:attr/textColorPrimary</color>
</resources>

View File

@@ -6790,6 +6790,10 @@
<string name="battery_usage_screen_footer_empty">Battery usage data will be available after you use your phone for a few hours</string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for battery chart view. -->
<string name="battery_usage_chart">Battery usage chart</string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for daily battery chart view. -->
<string name="daily_battery_usage_chart">Daily battery usage chart</string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for hourly battery chart view. -->
<string name="hourly_battery_usage_chart">Hourly battery usage chart</string>
<!-- Process Stats strings -->
<skip />

View File

@@ -65,7 +65,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private static final String TAG = "BatteryChartPreferenceController";
private static final String KEY_FOOTER_PREF = "battery_graph_footer";
private static final String PACKAGE_NAME_NONE = "none";
private static final int ENABLED_ICON_ALPHA = 255;
private static final int DISABLED_ICON_ALPHA = 255 / 3;
private static final long FADE_ANIMATION_DURATION = 350L;
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;
@@ -102,6 +105,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private boolean mIs24HourFormat;
private boolean mIsFooterPrefAdded = false;
private View mBatteryChartViewGroup;
private PreferenceScreen mPreferenceScreen;
private FooterPreference mFooterPreference;
// Daily view model only saves abbreviated day of week texts (e.g. MON). This field saves the
@@ -202,7 +206,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mPrefContext = screen.getContext();
mAppListPrefGroup = screen.findPreference(mPreferenceKey);
mAppListPrefGroup.setOrderingAsAdded(false);
mAppListPrefGroup.setTitle(mPrefContext.getString(R.string.battery_app_usage));
mAppListPrefGroup.setTitle("");
mFooterPreference = screen.findPreference(KEY_FOOTER_PREF);
// Removes footer first until usage data is loaded to avoid flashing.
if (mFooterPreference != null) {
@@ -260,6 +264,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
Log.d(TAG, "setBatteryHistoryMap() " + (batteryHistoryMap == null ? "null"
: ("size=" + batteryHistoryMap.size())));
// Ensure the battery chart group is visible for users.
animateBatteryChartViewGroup();
final BatteryLevelData batteryLevelData =
DataProcessor.getBatteryLevelData(mContext, mHandler, batteryHistoryMap,
batteryUsageMap -> {
@@ -267,6 +273,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
refreshUi();
});
Log.d(TAG, "getBatteryLevelData: " + batteryLevelData);
mMetricsFeatureProvider.action(
mPrefContext,
SettingsEnums.ACTION_BATTERY_HISTORY_LOADED,
getTotalHours(batteryLevelData));
if (batteryLevelData == null) {
mDailyTimestampFullTexts = null;
mDailyViewModel = null;
@@ -297,8 +308,13 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
void setBatteryChartView(@NonNull final BatteryChartView dailyChartView,
@NonNull final BatteryChartView hourlyChartView) {
final View parentView = (View) dailyChartView.getParent();
if (parentView != null && parentView.getId() == R.id.battery_chart_group) {
mBatteryChartViewGroup = (View) dailyChartView.getParent();
}
if (mDailyChartView != dailyChartView || mHourlyChartView != hourlyChartView) {
mHandler.post(() -> setBatteryChartViewInner(dailyChartView, hourlyChartView));
animateBatteryChartViewGroup();
}
}
@@ -313,7 +329,12 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mDailyChartIndex = trapezoidIndex;
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
refreshUi();
// TODO: Change to log daily data.
mMetricsFeatureProvider.action(
mPrefContext,
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
? SettingsEnums.ACTION_BATTERY_USAGE_DAILY_SHOW_ALL
: SettingsEnums.ACTION_BATTERY_USAGE_DAILY_TIME_SLOT,
mDailyChartIndex);
});
mHourlyChartView = hourlyChartView;
mHourlyChartView.setOnSelectListener(trapezoidIndex -> {
@@ -327,7 +348,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mPrefContext,
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
: SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
: SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT,
mHourlyChartIndex);
});
refreshUi();
}
@@ -452,6 +474,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
if (!isAdded) {
mAppListPrefGroup.addPreference(pref);
}
appIcon.setAlpha(pref.isEnabled() ? ENABLED_ICON_ALPHA : DISABLED_ICON_ALPHA);
prefIndex++;
}
}
@@ -601,6 +624,13 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return !DataProcessor.contains(packageName, mNotAllowShowSummaryPackages);
}
private void animateBatteryChartViewGroup() {
if (mBatteryChartViewGroup != null && mBatteryChartViewGroup.getAlpha() == 0) {
mBatteryChartViewGroup.animate().alpha(1f).setDuration(FADE_ANIMATION_DURATION)
.start();
}
}
private void addFooterPreferenceIfNeeded(boolean containAppItems) {
if (mIsFooterPrefAdded || mFooterPreference == null) {
return;
@@ -623,6 +653,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
&& mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL;
}
@VisibleForTesting
static int getTotalHours(final BatteryLevelData batteryLevelData) {
if (batteryLevelData == null) {
return 0;
}
List<Long> dailyTimestamps = batteryLevelData.getDailyBatteryLevels().getTimestamps();
return (int) ((dailyTimestamps.get(dailyTimestamps.size() - 1) - dailyTimestamps.get(0))
/ DateUtils.HOUR_IN_MILLIS);
}
private static List<String> generateTimestampDayOfWeekTexts(@NonNull final Context context,
@NonNull final List<Long> timestamps, final boolean isAbbreviation) {
final ArrayList<String> texts = new ArrayList<>();

View File

@@ -574,7 +574,7 @@ public class BatteryEntry {
break;
case BatteryConsumer.POWER_COMPONENT_BLUETOOTH:
name = context.getResources().getString(R.string.power_bluetooth);
iconId = com.android.internal.R.drawable.ic_settings_bluetooth;
iconId = R.drawable.ic_settings_bluetooth;
break;
case BatteryConsumer.POWER_COMPONENT_CAMERA:
name = context.getResources().getString(R.string.power_camera);
@@ -598,7 +598,7 @@ public class BatteryEntry {
break;
case BatteryConsumer.POWER_COMPONENT_WIFI:
name = context.getResources().getString(R.string.power_wifi);
iconId = R.drawable.ic_settings_wireless;
iconId = R.drawable.ic_settings_wireless_no_theme;
break;
case BatteryConsumer.POWER_COMPONENT_IDLE:
case BatteryConsumer.POWER_COMPONENT_MEMORY:

View File

@@ -106,12 +106,11 @@ public class BatteryHistoryPreference extends Preference {
return;
}
if (mIsChartGraphEnabled) {
final TextView companionTextView = (TextView) view.findViewById(R.id.companion_text);
mDailyChartView = (BatteryChartView) view.findViewById(R.id.daily_battery_chart);
mDailyChartView.setCompanionTextView(
(TextView) view.findViewById(R.id.companion_text));
mDailyChartView.setCompanionTextView(companionTextView);
mHourlyChartView = (BatteryChartView) view.findViewById(R.id.hourly_battery_chart);
mHourlyChartView.setCompanionTextView(
(TextView) view.findViewById(R.id.companion_text));
mHourlyChartView.setCompanionTextView(companionTextView);
if (mChartPreferenceController != null) {
mChartPreferenceController.setBatteryChartView(mDailyChartView, mHourlyChartView);
}

View File

@@ -630,6 +630,18 @@ public final class BatteryChartPreferenceControllerTest {
.isFalse();
}
@Test
public void getTotalHours_getExpectedResult() {
Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = createBatteryHistoryMap(60);
BatteryLevelData batteryLevelData = DataProcessor.getBatteryLevelData(mContext, null,
batteryHistoryMap, null);
final int totalHour = BatteryChartPreferenceController.getTotalHours(batteryLevelData);
// Only calculate the even hours.
assertThat(totalHour).isEqualTo(58);
}
private static Long generateTimestamp(int index) {
// "2021-04-23 07:00:00 UTC" + index hours
return 1619247600000L + index * DateUtils.HOUR_IN_MILLIS;

View File

@@ -307,7 +307,7 @@ public class BatteryEntryTest {
R.drawable.ic_settings_aod);
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
R.string.power_bluetooth,
com.android.internal.R.drawable.ic_settings_bluetooth);
R.drawable.ic_settings_bluetooth);
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_CAMERA,
R.string.power_camera,
R.drawable.ic_settings_camera);
@@ -325,7 +325,7 @@ public class BatteryEntryTest {
R.drawable.ic_settings_display);
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_WIFI,
R.string.power_wifi,
R.drawable.ic_settings_wireless);
R.drawable.ic_settings_wireless_no_theme);
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_IDLE,
R.string.power_idle,
R.drawable.ic_settings_phone_idle);