Merge "Update app usage page power summary" into sc-v2-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8f2c34e..1ba4d4d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6560,6 +6560,8 @@
<string name="battery_not_usage">No usage from last full charge</string>
<!-- Description for no any battery usage for past 24 hr [CHAR LIMIT=120] -->
<string name="battery_not_usage_24hr">No usage for past 24 hr</string>
+ <!-- Description for no usage time but have battery usage [CHAR LIMIT=120] -->
+ <string name="battery_usage_without_time"></string>
<!-- Graph subtext displayed to user when enhanced battery estimate is being used [CHAR LIMIT=120] -->
<string name="advanced_battery_graph_subtext">Battery left estimate is based on your device usage</string>
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 8019d0a..0d0cdba 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -326,10 +326,7 @@
}
if (mEnableTriState) {
- final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
- final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
- final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
- controller.setSummary(getAppActiveTime(foregroundTimeMs, backgroundTimeMs, slotTime));
+ controller.setSummary(getAppActiveTime(bundle));
}
controller.done(context, true /* rebindActions */);
@@ -493,16 +490,21 @@
mOptimizationMode = mBatteryOptimizeUtils.getAppOptimizationMode();
}
- private CharSequence getAppActiveTime(
- long foregroundTimeMs, long backgroundTimeMs, String slotTime) {
+ private CharSequence getAppActiveTime(Bundle bundle) {
+ final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
+ final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
+ final int consumedPower = bundle.getInt(EXTRA_POWER_USAGE_AMOUNT);
+ final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
final CharSequence usageTimeSummary;
final PowerUsageFeatureProvider powerFeatureProvider =
FeatureFactory.getFactory(getContext()).getPowerUsageFeatureProvider(getContext());
if (totalTimeMs == 0) {
+ final int batteryWithoutUsageTime = consumedPower > 0
+ ? R.string.battery_usage_without_time : R.string.battery_not_usage_24hr;
usageTimeSummary = getText(powerFeatureProvider.isChartGraphEnabled(getContext())
- ? R.string.battery_not_usage_24hr : R.string.battery_not_usage);
+ ? batteryWithoutUsageTime : R.string.battery_not_usage);
} else if (slotTime == null) {
// Shows summary text with past 24 hr or full charge if slot time is null.
usageTimeSummary = powerFeatureProvider.isChartGraphEnabled(getContext())
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index a2e78c3..3501726 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -438,6 +438,21 @@
}
@Test
+ public void testInitHeader_noUsageTimeButConsumedPower_hasEmptySummary() {
+ Bundle bundle = new Bundle(3);
+ bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
+ bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
+ bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
+ when(mFragment.getArguments()).thenReturn(bundle);
+
+ mFragment.initHeader();
+
+ ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+ verify(mEntityHeaderController).setSummary(captor.capture());
+ assertThat(captor.getValue().toString()).isEmpty();
+ }
+
+ @Test
public void testInitHeader_backgroundTwoMinForegroundZero_hasCorrectSummary() {
final long backgroundTimeTwoMinutes = 120000;
final long foregroundTimeZero = 0;