From 4242ee0dd4244fcf90b38a941ae61116d8e88127 Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Tue, 15 Aug 2017 11:01:07 -0700 Subject: [PATCH] Set preference invisible when no anomaly In the previous code path, we will create an invisible anomaly preference and update it to visible if it contains any anomaly. However, when anomaly is dismissed we don't reset preference to invisible. So, this cl adds code to set it to invisible explicitly when anomaly list is empty. Bug: 64617126 Test: RunSettingsRoboTests Change-Id: Ie7a3498da91243f05f4c47fb1cc5f67b177d04b1 --- .../anomaly/AnomalySummaryPreferenceController.java | 2 ++ .../AnomalySummaryPreferenceControllerTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java b/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java index 59c8b2c6838..6bfc9ffb76a 100644 --- a/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java +++ b/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceController.java @@ -102,6 +102,8 @@ public class AnomalySummaryPreferenceController { mAnomalyPreference.setTitle(title); mAnomalyPreference.setSummary(summary); + } else { + mAnomalyPreference.setVisible(false); } } 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 72d8b691866..8297e810b60 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java @@ -106,6 +106,16 @@ public class AnomalySummaryPreferenceControllerTest { assertThat(mPreference.getSummary()).isEqualTo("Keeping device awake"); } + @Test + public void testUpdateAnomalySummaryPreference_emptyAnomaly_preferenceInvisible() { + mPreference.setVisible(true); + mAnomalyList.clear(); + + mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList); + + assertThat(mPreference.isVisible()).isFalse(); + } + @Test public void testUpdateAnomalySummaryPreference_multipleAnomalies_showCorrectSummary() { mAnomalyList.add(createTestAnomaly());