Merge "Update app usage page active time column" into sc-dev
diff --git a/res/xml/power_usage_detail.xml b/res/xml/power_usage_detail.xml
index 0258f8d..c4f038e 100644
--- a/res/xml/power_usage_detail.xml
+++ b/res/xml/power_usage_detail.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2017 The Android Open Source Project
+ Copyright (C) 2021 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.
@@ -23,12 +23,10 @@
android:key="header_view"
android:layout="@layout/settings_entity_header"
android:selectable="false"
- android:order="-10000"
settings:allowDividerBelow="true"/>
<com.android.settingslib.widget.ActionButtonsPreference
- android:key="action_buttons"
- android:order="-9999"/>
+ android:key="action_buttons"/>
<PreferenceCategory
android:title="@string/battery_detail_manage_title"
@@ -72,23 +70,7 @@
</PreferenceCategory>
- <PreferenceCategory
- android:title="@string/battery_detail_info_title">
-
- <Preference
- android:key="app_usage_foreground"
- android:title="@string/battery_detail_foreground"
- android:selectable="false"/>
-
- <Preference
- android:key="app_usage_background"
- android:title="@string/battery_detail_background"
- android:selectable="false"/>
-
- </PreferenceCategory>
-
<com.android.settingslib.widget.FooterPreference
- android:order="100"
android:key="app_usage_footer_preference"
android:title="@string/manager_battery_usage_footer"
android:selectable="true"
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 6d73359..9b17544 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -292,31 +292,29 @@
controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
}
+ final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
+ final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
+ final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
+ //TODO(b/178197718) Refine the layout
+ controller.setSummary(TextUtils.expandTemplate(
+ getText(R.string.battery_total_and_background_usage),
+ StringUtil.formatElapsedTime(
+ getContext(),
+ totalTimeMs,
+ /* withSeconds */ false,
+ /* collapseTimeUnit */ false),
+ StringUtil.formatElapsedTime(
+ getContext(),
+ backgroundTimeMs,
+ /* withSeconds */ false,
+ /* collapseTimeUnit */ false)));
+
controller.done(context, true /* rebindActions */);
}
@VisibleForTesting
void initPreference() {
- final Bundle bundle = getArguments();
final Context context = getContext();
-
- final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
- final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
- mForegroundPreference.setSummary(
- TextUtils.expandTemplate(getText(R.string.battery_used_for),
- StringUtil.formatElapsedTime(
- context,
- foregroundTimeMs,
- /* withSeconds */ false,
- /* collapseTimeUnit */ false)));
- mBackgroundPreference.setSummary(
- TextUtils.expandTemplate(getText(R.string.battery_active_for),
- StringUtil.formatElapsedTime(
- context,
- backgroundTimeMs,
- /* withSeconds */ false,
- /* collapseTimeUnit */ false)));
-
final String stateString;
final String footerString;
//TODO(b/178197718) Update strings
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 820607f..8a776a3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -27,6 +27,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -267,6 +268,17 @@
}
@Test
+ public void testInitHeader_hasCorrectSummary() {
+ mFragment.mAppEntry = null;
+ mFragment.initHeader();
+
+ ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+ verify(mEntityHeaderController).setSummary(captor.capture());
+ assertThat(captor.getValue().toString())
+ .isEqualTo("0 min total • 0 min background for past 24 hr");
+ }
+
+ @Test
public void testStartBatteryDetailPage_hasBasicData() {
AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment,
mBatteryEntry, USAGE_PERCENT);
@@ -354,26 +366,6 @@
}
@Test
- public void testInitPreference_hasCorrectSummary() {
- Bundle bundle = new Bundle(4);
- bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, BACKGROUND_TIME_MS);
- bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, FOREGROUND_TIME_MS);
- bundle.putString(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT, USAGE_PERCENT);
- bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, POWER_MAH);
- when(mFragment.getArguments()).thenReturn(bundle);
-
- doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
- R.string.battery_used_for);
- doReturn(mContext.getText(R.string.battery_active_for)).when(mFragment).getText(
- R.string.battery_active_for);
-
- mFragment.initPreference();
-
- assertThat(mForegroundPreference.getSummary().toString()).isEqualTo("Used for 0 min");
- assertThat(mBackgroundPreference.getSummary().toString()).isEqualTo("Active for 0 min");
- }
-
- @Test
public void testInitPreference_isValidPackageName_hasCorrectString() {
when(mBatteryOptimizeUtils.isValidPackageName()).thenReturn(false);