[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
diff --git a/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java b/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java
index 032649c..ee46bdb 100644
--- a/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java
+++ b/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java
@@ -36,13 +36,13 @@
 
     @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 c2d99a6..f7962eb 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 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 @@
     }
 
     @Test
-    public void isAlwaysAvailable() {
-        assertThat(mController.isAvailable()).isTrue();
+    public void isAvailable_withInitialEmptyGroup_shouldBeFalse() {
+        assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
@@ -69,7 +69,7 @@
         mController.removeAllChildren();
 
         verify(mCategory).removeAll();
-        verify(mCategory).setVisible(false);
+        verify(mCategory, times(2)).setVisible(false);
     }
 
     @Test
@@ -79,7 +79,7 @@
 
         verify(mCategory).addPreference(pref);
         verify(mCategory, atLeastOnce()).setVisible(true);
-        verify(mCategory, never()).setVisible(false);
+        verify(mCategory).setVisible(false);
     }
 
     @Test