Merge "Fix forget button on wifi details page."
This commit is contained in:
committed by
Android (Google) Code Review
commit
22e4051ca9
@@ -149,7 +149,6 @@ public class WifiDetailPreferenceController extends PreferenceController impleme
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
mWifiInfo = mWifiManager.getConnectionInfo();
|
mWifiInfo = mWifiManager.getConnectionInfo();
|
||||||
mWifiConfig = mWifiManager.getWifiApConfiguration();
|
|
||||||
|
|
||||||
refreshFromWifiInfo();
|
refreshFromWifiInfo();
|
||||||
setIpText();
|
setIpText();
|
||||||
@@ -257,4 +256,17 @@ public class WifiDetailPreferenceController extends PreferenceController impleme
|
|||||||
}
|
}
|
||||||
mDnsPref.setDetailText(builder.toString());
|
mDnsPref.setDetailText(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forgets the wifi network associated with this preference.
|
||||||
|
*/
|
||||||
|
public void forgetNetwork() {
|
||||||
|
if (mWifiConfig.ephemeral) {
|
||||||
|
mWifiManager.disableEphemeralNetwork(mWifiConfig.SSID);
|
||||||
|
} else if (mWifiConfig.isPasspoint()) {
|
||||||
|
mWifiManager.removePasspointConfiguration(mWifiConfig.FQDN);
|
||||||
|
} else {
|
||||||
|
mWifiManager.forget(mWifiConfig.networkId, null /* action listener */);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import android.content.Context;
|
|||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
@@ -69,17 +70,9 @@ public class WifiNetworkDetailsFragment extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void forgetNetwork() {
|
private void forgetNetwork() {
|
||||||
WifiInfo info = mWifiDetailPreferenceController.getWifiInfo();
|
|
||||||
mMetricsFeatureProvider.action(getActivity(), MetricsProto.MetricsEvent.ACTION_WIFI_FORGET);
|
mMetricsFeatureProvider.action(getActivity(), MetricsProto.MetricsEvent.ACTION_WIFI_FORGET);
|
||||||
if (!info.isEphemeral()) {
|
mWifiDetailPreferenceController.forgetNetwork();
|
||||||
// Network is active but has no network ID - must be ephemeral.
|
mForgetButton.setEnabled(false);
|
||||||
mWifiManager.disableEphemeralNetwork(
|
|
||||||
AccessPoint.convertToQuotedString(info.getSSID()));
|
|
||||||
} else if (mAccessPoint.getConfig().isPasspoint()) {
|
|
||||||
mWifiManager.removePasspointConfiguration(mAccessPoint.getConfig().FQDN);
|
|
||||||
} else {
|
|
||||||
mWifiManager.forget(info.getNetworkId(), null /* action listener */);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -84,8 +84,6 @@ public class WifiDetailPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mLifecycle = new Lifecycle();
|
mLifecycle = new Lifecycle();
|
||||||
mController = new WifiDetailPreferenceController(
|
|
||||||
mockAccessPoint, mContext, mLifecycle, mockWifiManager);
|
|
||||||
|
|
||||||
when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfig);
|
when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfig);
|
||||||
when(mockAccessPoint.getLevel()).thenReturn(LEVEL);
|
when(mockAccessPoint.getLevel()).thenReturn(LEVEL);
|
||||||
@@ -93,11 +91,13 @@ public class WifiDetailPreferenceControllerTest {
|
|||||||
when(mockAccessPoint.getRssi()).thenReturn(RSSI);
|
when(mockAccessPoint.getRssi()).thenReturn(RSSI);
|
||||||
when(mockAccessPoint.getSecurityString(false)).thenReturn(SECURITY);
|
when(mockAccessPoint.getSecurityString(false)).thenReturn(SECURITY);
|
||||||
|
|
||||||
|
mController = new WifiDetailPreferenceController(
|
||||||
|
mockAccessPoint, mContext, mLifecycle, mockWifiManager);
|
||||||
|
|
||||||
setupMockedPreferenceScreen();
|
setupMockedPreferenceScreen();
|
||||||
|
|
||||||
when(mockWifiInfo.getRssi()).thenReturn(RSSI);
|
when(mockWifiInfo.getRssi()).thenReturn(RSSI);
|
||||||
when(mockWifiManager.getConnectionInfo()).thenReturn(mockWifiInfo);
|
when(mockWifiManager.getConnectionInfo()).thenReturn(mockWifiInfo);
|
||||||
when(mockWifiManager.getWifiApConfiguration()).thenReturn(mockWifiConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupMockedPreferenceScreen() {
|
private void setupMockedPreferenceScreen() {
|
||||||
@@ -139,7 +139,6 @@ public class WifiDetailPreferenceControllerTest {
|
|||||||
mController.onResume();
|
mController.onResume();
|
||||||
|
|
||||||
verify(mockWifiManager).getConnectionInfo();
|
verify(mockWifiManager).getConnectionInfo();
|
||||||
verify(mockWifiManager).getWifiApConfiguration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -178,4 +177,29 @@ public class WifiDetailPreferenceControllerTest {
|
|||||||
|
|
||||||
verify(mockSignalStrengthPref).setDetailText(expectedStrength);
|
verify(mockSignalStrengthPref).setDetailText(expectedStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
mController = new WifiDetailPreferenceController(
|
||||||
|
mockAccessPoint, mContext, mLifecycle, mockWifiManager);
|
||||||
|
|
||||||
|
mController.forgetNetwork();
|
||||||
|
|
||||||
|
verify(mockWifiManager).disableEphemeralNetwork(wifiConfiguration.SSID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void forgetNetwork_saved() {
|
||||||
|
mockWifiConfig.networkId = 5;
|
||||||
|
|
||||||
|
mController.forgetNetwork();
|
||||||
|
|
||||||
|
verify(mockWifiManager).forget(mockWifiConfig.networkId, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user