Fix NPE when forgetting networks.

- Fixed disablement of ephemeral networks
- Exit out of the fragment when Forget is pressed

Bug: 36723238
Test: m RunSettingsRoboTests and manual testing
Change-Id: I83c09a44dbef0f02a452dc8c3163523a27bd4b63
This commit is contained in:
Amin Shaikh
2017-03-31 13:56:53 -07:00
parent 8fc0d1f948
commit 3c0d5ff3d1
3 changed files with 56 additions and 23 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.wifi.details;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -93,14 +94,14 @@ public class WifiDetailPreferenceControllerTest {
when(mockAccessPoint.getRssi()).thenReturn(RSSI);
when(mockAccessPoint.getSecurityString(false)).thenReturn(SECURITY);
when(mockWifiInfo.getLinkSpeed()).thenReturn(LINK_SPEED);
when(mockWifiInfo.getRssi()).thenReturn(RSSI);
when(mockWifiManager.getConnectionInfo()).thenReturn(mockWifiInfo);
mController = new WifiDetailPreferenceController(
mockAccessPoint, mContext, mLifecycle, mockWifiManager);
setupMockedPreferenceScreen();
when(mockWifiInfo.getRssi()).thenReturn(RSSI);
when(mockWifiInfo.getLinkSpeed()).thenReturn(LINK_SPEED);
when(mockWifiManager.getConnectionInfo()).thenReturn(mockWifiInfo);
}
private void setupMockedPreferenceScreen() {
@@ -143,7 +144,8 @@ public class WifiDetailPreferenceControllerTest {
public void latestWifiInfoAndConfig_shouldBeFetchedOnResume() {
mController.onResume();
verify(mockWifiManager).getConnectionInfo();
// Once in construction, once in onResume
verify(mockWifiManager, times(2)).getConnectionInfo();
}
@Test
@@ -193,19 +195,41 @@ public class WifiDetailPreferenceControllerTest {
}
@Test
public void forgetNetwork_ephemeral() {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "ssid";
// WifiConfiguration#isEphemeral will not be visible in robolectric until O is supported
wifiConfiguration.ephemeral = true;
when(mockAccessPoint.getConfig()).thenReturn(wifiConfiguration);
public void canForgetNetwork_noNetwork() {
when(mockAccessPoint.getConfig()).thenReturn(null);
mController = new WifiDetailPreferenceController(
mockAccessPoint, mContext, mLifecycle, mockWifiManager);
assertThat(mController.canForgetNetwork()).isFalse();
}
@Test
public void canForgetNetwork_ephemeral() {
when(mockWifiInfo.isEphemeral()).thenReturn(true);
when(mockAccessPoint.getConfig()).thenReturn(null);
mController = new WifiDetailPreferenceController(
mockAccessPoint, mContext, mLifecycle, mockWifiManager);
assertThat(mController.canForgetNetwork()).isTrue();
}
@Test
public void canForgetNetwork_saved() {
assertThat(mController.canForgetNetwork()).isTrue();
}
@Test
public void forgetNetwork_ephemeral() {
String ssid = "ssid";
when(mockWifiInfo.isEphemeral()).thenReturn(true);
when(mockWifiInfo.getSSID()).thenReturn(ssid);
mController.forgetNetwork();
verify(mockWifiManager).disableEphemeralNetwork(wifiConfiguration.SSID);
verify(mockWifiManager).disableEphemeralNetwork(ssid);
}
@Test