diff --git a/res/values/strings.xml b/res/values/strings.xml
index 81e3b0fc366..c0ec31e6ff7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7410,11 +7410,11 @@
High usage
-
- %1$s behaving abnormally
-
-
- %1$d apps behaving abnormally
+
+
+ - %1$s behaving abnormally
+ - %2$d apps behaving abnormally
+
Not optimized
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index 3c685c04d50..8addcabf28d 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -26,7 +26,8 @@
android:layout="@layout/battery_header"/>
+ android:key="high_usage"
+ android:title="@string/power_high_usage_title"/>
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index fc779510647..ac243f314e9 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -139,7 +139,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
@Override
public void onLoadFinished(Loader> loader, List data) {
// show high usage preference if possible
- mAnomalySummaryPreferenceController.updateHighUsagePreference(data);
+ mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(data);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java b/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java
index dc47a218448..49fe4e8b49c 100644
--- a/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java
@@ -16,10 +16,12 @@
package com.android.settings.fuelgauge.anomaly;
+import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.PowerUsageAnomalyDetails;
@@ -70,12 +72,18 @@ public class AnomalySummaryPreferenceController {
*
* @param anomalies used to update the summary, this method will store a reference of it
*/
- public void updateHighUsagePreference(List anomalies) {
+ public void updateAnomalySummaryPreference(List anomalies) {
+ final Context context = mFragment.getContext();
mAnomalies = anomalies;
if (!mAnomalies.isEmpty()) {
mAnomalyPreference.setVisible(true);
- //TODO(b/36924669): update summary for anomaly preference
+ final int count = mAnomalies.size();
+ final String summary = context.getResources().getQuantityString(
+ R.plurals.power_high_usage_summary, count,
+ mAnomalies.get(0).displayName, count);
+
+ mAnomalyPreference.setSummary(summary);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
index 44a10ca5bca..6a68fd23514 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
@@ -53,6 +53,7 @@ public class AnomalySummaryPreferenceControllerTest {
@Anomaly.AnomalyType
private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
private static final String PACKAGE_NAME = "com.android.app";
+ private static final String DISPLAY_NAME = "app";
private static final int UID = 111;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -75,32 +76,47 @@ public class AnomalySummaryPreferenceControllerTest {
mContext = RuntimeEnvironment.application;
mPreference = new Preference(mContext);
mPreference.setKey(AnomalySummaryPreferenceController.ANOMALY_KEY);
- when(mFragment.getPreferenceManager().findPreference(any())).thenReturn(mPreference);
+ when(mFragment.getPreferenceScreen().findPreference(any())).thenReturn(mPreference);
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
+ when(mFragment.getContext()).thenReturn(mContext);
mAnomalyList = new ArrayList<>();
- Anomaly anomaly = new Anomaly.Builder()
- .setType(ANOMALY_TYPE)
- .setUid(UID)
- .setPackageName(PACKAGE_NAME)
- .build();
- mAnomalyList.add(anomaly);
mAnomalySummaryPreferenceController = new AnomalySummaryPreferenceController(
mSettingsActivity, mFragment);
}
@Test
- public void testUpdateHighUsagePreference_hasCorrectData() {
- mAnomalySummaryPreferenceController.updateHighUsagePreference(mAnomalyList);
+ public void testUpdateHighUsageSummaryPreference_hasCorrectData() {
+ mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
- //add more test when this method is complete
assertThat(mAnomalySummaryPreferenceController.mAnomalies).isEqualTo(mAnomalyList);
}
+ @Test
+ public void testUpdateAnomalySummaryPreference_oneAnomaly_showCorrectSummary() {
+ mAnomalyList.add(createTestAnomaly());
+
+ mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
+
+ assertThat(mPreference.getSummary()).isEqualTo("app behaving abnormally");
+ }
+
+ @Test
+ public void testUpdateAnomalySummaryPreference_multipleAnomalies_showCorrectSummary() {
+ mAnomalyList.add(createTestAnomaly());
+ mAnomalyList.add(createTestAnomaly());
+
+ mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
+
+ assertThat(mPreference.getSummary()).isEqualTo("2 apps behaving abnormally");
+ }
+
@Test
public void testOnPreferenceTreeClick_oneAnomaly_showDialog() {
+
+ mAnomalyList.add(createTestAnomaly());
mAnomalySummaryPreferenceController.mAnomalies = mAnomalyList;
mAnomalySummaryPreferenceController.onPreferenceTreeClick(mPreference);
@@ -110,4 +126,13 @@ public class AnomalySummaryPreferenceControllerTest {
verify(mFragmentTransaction).commit();
}
+ private Anomaly createTestAnomaly() {
+ return new Anomaly.Builder()
+ .setType(ANOMALY_TYPE)
+ .setUid(UID)
+ .setPackageName(PACKAGE_NAME)
+ .setDisplayName(DISPLAY_NAME)
+ .build();
+ }
+
}