Only show Sign In button for connected network

The Sign In button may appeared in details page for disconnected network
if current network is Captive Portal network. Should hide the button
for disconnected network.

Bug: 129514576
Test: make RunSettingsRoboTests -j32 ROBOTEST_FILTER=com.android.settings.wifi.details.WifiDetailPreferenceControllerTest
Test: manual test
Change-Id: I8b4f79e7ba731ce83c49576fffd3e78a27598be3
This commit is contained in:
clownshen
2019-04-01 16:01:06 +08:00
committed by Clown SHEN
parent 531a87bfd5
commit 5c2637d6d0
2 changed files with 22 additions and 2 deletions

View File

@@ -838,7 +838,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
* Returns whether the user can sign into the network represented by this preference. * Returns whether the user can sign into the network represented by this preference.
*/ */
private boolean canSignIntoNetwork() { private boolean canSignIntoNetwork() {
return WifiUtils.canSignIntoNetwork(mNetworkCapabilities); return mAccessPoint.isActive() && WifiUtils.canSignIntoNetwork(mNetworkCapabilities);
} }
/** /**

View File

@@ -1404,6 +1404,27 @@ public class WifiDetailPreferenceControllerTest {
.action(mockActivity, MetricsProto.MetricsEvent.ACTION_WIFI_SIGNIN); .action(mockActivity, MetricsProto.MetricsEvent.ACTION_WIFI_SIGNIN);
} }
@Test
public void testSignInButton_shouldHideSignInButtonForDisconnectedNetwork() {
setUpForDisconnectedNetwork();
NetworkCapabilities nc = makeNetworkCapabilities();
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
when(mockConnectivityManager.getNetworkCapabilities(mockNetwork))
.thenReturn(new NetworkCapabilities(nc));
// verify onResume
displayAndResume();
verify(mockButtonsPref, never()).setButton2Visible(true);
verify(mockButtonsPref).setButton2Visible(false);
// verify onCapabilitiesChanged
updateNetworkCapabilities(nc);
verify(mockButtonsPref, never()).setButton2Visible(true);
verify(mockButtonsPref).setButton2Visible(false);
}
@Test @Test
public void testRefreshRssiViews_shouldNotUpdateIfLevelIsSame() { public void testRefreshRssiViews_shouldNotUpdateIfLevelIsSame() {
displayAndResume(); displayAndResume();
@@ -1437,7 +1458,6 @@ public class WifiDetailPreferenceControllerTest {
verify(mockSignalStrengthPref, times(2)).setVisible(false); verify(mockSignalStrengthPref, times(2)).setVisible(false);
} }
private ActionButtonsPreference createMock() { private ActionButtonsPreference createMock() {
final ActionButtonsPreference pref = mock(ActionButtonsPreference.class); final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
when(pref.setButton1Text(anyInt())).thenReturn(pref); when(pref.setButton1Text(anyInt())).thenReturn(pref);