Update app usage page power summary

- Present empty string when this app consumed power but no usage time,
 usually they are some system components

Bug: 197749108
Test: make -j64 RunSettingsRoboTest
Change-Id: I1e88babb30c871748fa1f5fc23c7b4d834e384fd
This commit is contained in:
Wesley.CW Wang
2021-10-21 15:54:57 +08:00
parent 541f0e447f
commit 23a5fb5e74
3 changed files with 26 additions and 7 deletions

View File

@@ -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>

View File

@@ -326,10 +326,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
}
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 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
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())

View File

@@ -437,6 +437,21 @@ public class AdvancedPowerUsageDetailTest {
.isEqualTo("No usage for past 24 hr");
}
@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;