From 623e8570b9ec6441a38733b2012978ec4fea86f7 Mon Sep 17 00:00:00 2001 From: govenliu Date: Fri, 4 Oct 2019 18:14:53 +0800 Subject: [PATCH] [Wi-Fi] Un-relevant string flash then disappear in WiFi direct page. The "PEER DEVICES" and "REMEMBERED GROUPS" two strings appear then disappear suddenly. Solution: Set those two PreferenceGroups, which with empty preference child, invisible before showing. Bug: 141830944 Test: 1.Manual test. 2.Modify isAvailable() test case for make sure the initial visible of empty group is invisible. Change-Id: Ifb074ac758196096ca63b6f7fa1285f8148d98d4 --- .../wifi/p2p/P2pCategoryPreferenceController.java | 4 ++-- .../wifi/p2p/P2pCategoryPreferenceControllerTest.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java b/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java index 032649c1499..ee46bdb6b2c 100644 --- a/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java +++ b/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java @@ -36,13 +36,13 @@ public abstract class P2pCategoryPreferenceController extends AbstractPreference @Override public boolean isAvailable() { - return true; + return mCategory.getPreferenceCount() > 0; } @Override public void displayPreference(PreferenceScreen screen) { - super.displayPreference(screen); mCategory = screen.findPreference(getPreferenceKey()); + super.displayPreference(screen); } public void removeAllChildren() { diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java index c2d99a65d89..f7962ebfb94 100644 --- a/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java @@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -60,8 +60,8 @@ public class P2pCategoryPreferenceControllerTest { } @Test - public void isAlwaysAvailable() { - assertThat(mController.isAvailable()).isTrue(); + public void isAvailable_withInitialEmptyGroup_shouldBeFalse() { + assertThat(mController.isAvailable()).isFalse(); } @Test @@ -69,7 +69,7 @@ public class P2pCategoryPreferenceControllerTest { mController.removeAllChildren(); verify(mCategory).removeAll(); - verify(mCategory).setVisible(false); + verify(mCategory, times(2)).setVisible(false); } @Test @@ -79,7 +79,7 @@ public class P2pCategoryPreferenceControllerTest { verify(mCategory).addPreference(pref); verify(mCategory, atLeastOnce()).setVisible(true); - verify(mCategory, never()).setVisible(false); + verify(mCategory).setVisible(false); } @Test