summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-04-03 06:22:43 -0700
committerRoshan Pius <rpius@google.com>2020-04-03 20:28:47 -0700
commitbf4e6bf7df39b4f9ca982c0e3b72e6805b41e782 (patch)
tree982c76251dc25eebf00c808c416557acddc48c4e /tests
parentedbd063552857947211a0cae78ffc57ce707f8dd (diff)
ClientModeImpl: Disconnect if network is marked metered
1) If the network is marked metered from unmetered/none by either the app or user post connection, trigger a disconnect to ensure that all apps re-read the meteredness of the network (when connected back again). 2) If the network is marked unmetered/none from metered by either the app or user post connection, just update the network capabilities. Also, a) Modified the onNetworkUpdated() WifiConfigManager callback to include both the previous and new config to help clients compare what has changed. b) If a suggestion is being updated and the network is cached in WifiConfigManager (either because we're connected to that or was connectable in the recent past), trigger an immediate update of configuration. This ensures that any metered changes take effect immediately. c) Similarly for passpoint networks cached in WifiConfigManager, trigger an immediate of configuration. This ensures that any metered changes take effect immediately. d) Removed update of existing config in NetworkSuggestionNominator which is redundant with (b) e) Ensure that all configs sent out from WifiConfigManager callbacks have their passwords masked to ensure they're not accidentally sent out of the stack. f) Added a shell command to just add/update network config without triggering a connect immediately. Bug: 153127005 Test: atest com.android.server.wifi Test: Manual steps Suggestion Metered change (unmetered->metered): adb shell cmd wifi add-suggestion <ssid> open adb shell cmd wifi start-scan adb shell cmd wifi status -> connected as unmetered adb shell cmd wifi add-suggestion GoogleGuest open -m adb shell cmd wifi status -> disconnected adb shell cmd wifi status -> connected back as metered adb shell cmd wifi add-suggestion GoogleGuest open adb shell cmd wifi status -> remained connected, but changed to unmetered Saved network Metered change (unmetered->metered): adb shell cmd wifi add-network <ssid> open adb shell cmd wifi start-scan adb shell cmd wifi status -> connected as unmetered adb shell cmd wifi add-network GoogleGuest open -m adb shell cmd wifi status -> disconnected adb shell cmd wifi status -> connected back as metered adb shell cmd wifi add-network GoogleGuest open adb shell cmd wifi status -> remained connected, but changed to unmetered Change-Id: Id313a302dc529fcafa8e2d1a8442f748896cab89
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java190
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java14
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java85
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java41
5 files changed, 295 insertions, 50 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 1930cd15a..448cee1cc 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -16,6 +16,9 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_METERED;
+import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_NONE;
+import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_NOT_METERED;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NONE;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY;
@@ -47,6 +50,7 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
@@ -155,7 +159,6 @@ import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
@@ -2418,11 +2421,8 @@ public class ClientModeImplTest extends WifiBaseTest {
assertFalse(mCmi.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig));
}
- private void expectRegisterNetworkAgent() {
- expectRegisterNetworkAgent((config) -> { });
- }
-
- private void expectRegisterNetworkAgent(Consumer<NetworkAgentConfig> configChecker) {
+ private void expectRegisterNetworkAgent(Consumer<NetworkAgentConfig> configChecker,
+ Consumer<NetworkCapabilities> networkCapabilitiesChecker) {
// Expects that the code calls registerNetworkAgent and provides a way for the test to
// verify the messages sent through the NetworkAgent to ConnectivityService.
// We cannot just use a mock object here because mWifiNetworkAgent is private to CMI.
@@ -2430,23 +2430,34 @@ public class ClientModeImplTest extends WifiBaseTest {
ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
ArgumentCaptor<NetworkAgentConfig> configCaptor =
ArgumentCaptor.forClass(NetworkAgentConfig.class);
+ ArgumentCaptor<NetworkCapabilities> networkCapabilitiesCaptor =
+ ArgumentCaptor.forClass(NetworkCapabilities.class);
verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(),
- any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class),
+ any(NetworkInfo.class), any(LinkProperties.class),
+ networkCapabilitiesCaptor.capture(),
anyInt(), configCaptor.capture(), anyInt());
registerAsyncChannel((x) -> {
mNetworkAgentAsyncChannel = x;
}, messengerCaptor.getValue(), mNetworkAgentHandler);
configChecker.accept(configCaptor.getValue());
+ networkCapabilitiesChecker.accept(networkCapabilitiesCaptor.getValue());
mNetworkAgentAsyncChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
mLooper.dispatchAll();
}
- private void expectNetworkAgentMessage(int what, int arg1, int arg2, Object obj) {
- verify(mNetworkAgentHandler).handleMessage(argThat(msg ->
- what == msg.what && arg1 == msg.arg1 && arg2 == msg.arg2
- && Objects.equals(obj, msg.obj)));
+ private void expectNetworkAgentUpdateCapabilities(
+ Consumer<NetworkCapabilities> networkCapabilitiesChecker) {
+ // We cannot just use a mock object here because mWifiNetworkAgent is private to CMI.
+ // TODO (b/134538181): consider exposing WifiNetworkAgent and using mocks.
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ mLooper.dispatchAll();
+ verify(mNetworkAgentHandler).handleMessage(messageCaptor.capture());
+ Message message = messageCaptor.getValue();
+ assertNotNull(message);
+ assertEquals(NetworkAgent.EVENT_NETWORK_CAPABILITIES_CHANGED, message.what);
+ networkCapabilitiesChecker.accept((NetworkCapabilities) message.obj);
}
/**
@@ -2466,7 +2477,7 @@ public class ClientModeImplTest extends WifiBaseTest {
assertTrue(agentConfig.explicitlySelected);
assertFalse(agentConfig.acceptUnvalidated);
assertFalse(agentConfig.acceptPartialConnectivity);
- });
+ }, (cap) -> { });
}
/**
@@ -2486,7 +2497,7 @@ public class ClientModeImplTest extends WifiBaseTest {
assertFalse(agentConfig.explicitlySelected);
assertFalse(agentConfig.acceptUnvalidated);
assertTrue(agentConfig.acceptPartialConnectivity);
- });
+ }, (cap) -> { });
}
/**
@@ -2506,7 +2517,7 @@ public class ClientModeImplTest extends WifiBaseTest {
assertTrue(agentConfig.explicitlySelected);
assertTrue(agentConfig.acceptUnvalidated);
assertTrue(agentConfig.acceptPartialConnectivity);
- });
+ }, (cap) -> { });
}
/**
@@ -4817,4 +4828,155 @@ public class ClientModeImplTest extends WifiBaseTest {
assertEquals(mConnectedNetwork.trusted, mCmi.getWifiInfo().isTrusted());
assertEquals(mConnectedNetwork.osu, mCmi.getWifiInfo().isOsuAp());
}
+
+ /**
+ * Verify that we disconnect when we mark a previous unmetered network metered.
+ */
+ @Test
+ public void verifyDisconnectOnMarkingNetworkMetered() throws Exception {
+ connect();
+ expectRegisterNetworkAgent((config) -> { }, (cap) -> {
+ assertTrue(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+
+ WifiConfiguration oldConfig = new WifiConfiguration(mConnectedNetwork);
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_METERED;
+
+ mConfigUpdateListenerCaptor.getValue().onNetworkUpdated(mConnectedNetwork, oldConfig);
+ mLooper.dispatchAll();
+ assertEquals("DisconnectingState", getCurrentState().getName());
+ }
+
+ /**
+ * Verify that we only update capabilites when we mark a previous unmetered network metered.
+ */
+ @Test
+ public void verifyUpdateCapabilitiesOnMarkingNetworkUnmetered() throws Exception {
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_METERED;
+ connect();
+ expectRegisterNetworkAgent((config) -> { }, (cap) -> {
+ assertFalse(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ reset(mNetworkAgentHandler);
+
+ WifiConfiguration oldConfig = new WifiConfiguration(mConnectedNetwork);
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NOT_METERED;
+
+ mConfigUpdateListenerCaptor.getValue().onNetworkUpdated(mConnectedNetwork, oldConfig);
+ mLooper.dispatchAll();
+ assertEquals("ConnectedState", getCurrentState().getName());
+
+ expectNetworkAgentUpdateCapabilities((cap) -> {
+ assertTrue(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ }
+
+
+ /**
+ * Verify that we disconnect when we mark a previous unmetered network metered.
+ */
+ @Test
+ public void verifyDisconnectOnMarkingNetworkAutoMeteredWithMeteredHint() throws Exception {
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NOT_METERED;
+ connect();
+ expectRegisterNetworkAgent((config) -> { }, (cap) -> {
+ assertTrue(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ reset(mNetworkAgentHandler);
+
+ // Mark network metered none.
+ WifiConfiguration oldConfig = new WifiConfiguration(mConnectedNetwork);
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NONE;
+
+ // Set metered hint in WifiInfo (either via DHCP or ScanResult IE).
+ WifiInfo wifiInfo = mCmi.getWifiInfo();
+ wifiInfo.setMeteredHint(true);
+
+ mConfigUpdateListenerCaptor.getValue().onNetworkUpdated(mConnectedNetwork, oldConfig);
+ mLooper.dispatchAll();
+ assertEquals("DisconnectingState", getCurrentState().getName());
+ }
+
+ /**
+ * Verify that we only update capabilites when we mark a previous unmetered network metered.
+ */
+ @Test
+ public void verifyUpdateCapabilitiesOnMarkingNetworkAutoMeteredWithoutMeteredHint()
+ throws Exception {
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_METERED;
+ connect();
+ expectRegisterNetworkAgent((config) -> { }, (cap) -> {
+ assertFalse(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ reset(mNetworkAgentHandler);
+
+ WifiConfiguration oldConfig = new WifiConfiguration(mConnectedNetwork);
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NONE;
+
+ // Reset metered hint in WifiInfo.
+ WifiInfo wifiInfo = mCmi.getWifiInfo();
+ wifiInfo.setMeteredHint(false);
+
+ mConfigUpdateListenerCaptor.getValue().onNetworkUpdated(mConnectedNetwork, oldConfig);
+ mLooper.dispatchAll();
+ assertEquals("ConnectedState", getCurrentState().getName());
+
+ expectNetworkAgentUpdateCapabilities((cap) -> {
+ assertTrue(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ }
+
+ /**
+ * Verify that we do nothing on no metered change.
+ */
+ @Test
+ public void verifyDoNothingMarkingNetworkAutoMeteredWithMeteredHint() throws Exception {
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_METERED;
+ connect();
+ expectRegisterNetworkAgent((config) -> { }, (cap) -> {
+ assertFalse(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ reset(mNetworkAgentHandler);
+
+ // Mark network metered none.
+ WifiConfiguration oldConfig = new WifiConfiguration(mConnectedNetwork);
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NONE;
+
+ // Set metered hint in WifiInfo (either via DHCP or ScanResult IE).
+ WifiInfo wifiInfo = mCmi.getWifiInfo();
+ wifiInfo.setMeteredHint(true);
+
+ mConfigUpdateListenerCaptor.getValue().onNetworkUpdated(mConnectedNetwork, oldConfig);
+ mLooper.dispatchAll();
+ assertEquals("ConnectedState", getCurrentState().getName());
+
+ verifyNoMoreInteractions(mNetworkAgentHandler);
+ }
+
+ /**
+ * Verify that we do nothing on no metered change.
+ */
+ @Test
+ public void verifyDoNothingMarkingNetworkAutoMeteredWithoutMeteredHint() throws Exception {
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NOT_METERED;
+ connect();
+ expectRegisterNetworkAgent((config) -> { }, (cap) -> {
+ assertTrue(cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
+ });
+ reset(mNetworkAgentHandler);
+
+ // Mark network metered none.
+ WifiConfiguration oldConfig = new WifiConfiguration(mConnectedNetwork);
+ mConnectedNetwork.meteredOverride = METERED_OVERRIDE_NONE;
+
+ // Reset metered hint in WifiInfo.
+ WifiInfo wifiInfo = mCmi.getWifiInfo();
+ wifiInfo.setMeteredHint(false);
+
+ mConfigUpdateListenerCaptor.getValue().onNetworkUpdated(mConnectedNetwork, oldConfig);
+ mLooper.dispatchAll();
+ assertEquals("ConnectedState", getCurrentState().getName());
+
+ verifyNoMoreInteractions(mNetworkAgentHandler);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
index 17bb4c133..f8084e374 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
@@ -470,11 +470,6 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
.isNetworkTemporarilyDisabledByUser(anyString());
verify(mWifiConfigManager)
.getConfiguredNetwork(suggestions[0].wns.wifiConfiguration.getKey());
- verify(mWifiConfigManager).addOrUpdateNetwork(
- argThat(new WifiConfigMatcher(suggestions[0].wns.wifiConfiguration)),
- eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName));
- verify(mWifiConfigManager).getConfiguredNetwork(
- suggestions[0].wns.wifiConfiguration.networkId);
// Verify we did not try to add any new networks or other interactions with
// WifiConfigManager.
verifyNoMoreInteractions(mWifiConfigManager);
@@ -586,11 +581,6 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
.isNetworkTemporarilyDisabledByUser(anyString());
verify(mWifiConfigManager).getConfiguredNetwork(eq(
suggestions[0].wns.wifiConfiguration.getKey()));
- verify(mWifiConfigManager).addOrUpdateNetwork(
- argThat(new WifiConfigMatcher(suggestions[0].wns.wifiConfiguration)),
- eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName));
- verify(mWifiConfigManager).getConfiguredNetwork(
- suggestions[0].wns.wifiConfiguration.networkId);
verify(mWifiConfigManager).tryEnableNetwork(eq(
suggestions[0].wns.wifiConfiguration.networkId));
// Verify we did not try to add any new networks or other interactions with
@@ -655,11 +645,6 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
.isNetworkTemporarilyDisabledByUser(anyString());
verify(mWifiConfigManager).getConfiguredNetwork(eq(
suggestions[0].wns.wifiConfiguration.getKey()));
- verify(mWifiConfigManager).addOrUpdateNetwork(
- argThat(new WifiConfigMatcher(suggestions[0].wns.wifiConfiguration)),
- eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName));
- verify(mWifiConfigManager).getConfiguredNetwork(
- suggestions[0].wns.wifiConfiguration.networkId);
verify(mWifiConfigManager).tryEnableNetwork(eq(
suggestions[0].wns.wifiConfiguration.networkId));
// Verify we did not try to add any new networks or other interactions with
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index a8928313a..e6741d069 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -507,7 +507,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Now change BSSID for the network.
assertAndSetNetworkBSSID(openNetwork, TEST_BSSID);
// Change the trusted bit.
- openNetwork.trusted = true;
+ openNetwork.trusted = false;
verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(openNetwork);
// Now verify that the modification has been effective.
@@ -515,8 +515,16 @@ public class WifiConfigManagerTest extends WifiBaseTest {
mWifiConfigManager.getConfiguredNetworksWithPasswords();
WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate(
networks, retrievedNetworks);
- verify(mWcmListener).onNetworkUpdated(wifiConfigCaptor.capture());
- assertEquals(openNetwork.networkId, wifiConfigCaptor.getValue().networkId);
+ verify(mWcmListener).onNetworkUpdated(
+ wifiConfigCaptor.capture(), wifiConfigCaptor.capture());
+ WifiConfiguration newConfig = wifiConfigCaptor.getAllValues().get(1);
+ WifiConfiguration oldConfig = wifiConfigCaptor.getAllValues().get(0);
+ assertEquals(openNetwork.networkId, newConfig.networkId);
+ assertFalse(newConfig.trusted);
+ assertEquals(TEST_BSSID, newConfig.BSSID);
+ assertEquals(openNetwork.networkId, oldConfig.networkId);
+ assertTrue(oldConfig.trusted);
+ assertNull(oldConfig.BSSID);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index bb090cae5..9048cb088 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -106,6 +106,7 @@ import java.util.stream.Collectors;
*/
@SmallTest
public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
+
private static final String TEST_PACKAGE_1 = "com.test12345";
private static final String TEST_PACKAGE_2 = "com.test54321";
private static final String TEST_APP_NAME_1 = "test12345";
@@ -516,7 +517,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
* Verify that modify networks that are already active is allowed.
*/
@Test
- public void testAddNetworkSuggestionsSuccessOnInPlaceModification() {
+ public void testAddNetworkSuggestionsSuccessOnInPlaceModificationWhenNotInWcm() {
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, true);
List<WifiNetworkSuggestion> networkSuggestionList1 =
@@ -528,10 +529,64 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
TEST_PACKAGE_1, TEST_FEATURE));
- // Modify the original suggestion.
+ // Assert that the original config was not metered.
+ assertEquals(WifiConfiguration.METERED_OVERRIDE_NONE,
+ networkSuggestion.wifiConfiguration.meteredOverride);
+
+ // Nothing in WCM.
+ when(mWifiConfigManager.getConfiguredNetwork(networkSuggestion.wifiConfiguration.getKey()))
+ .thenReturn(null);
+
+ // Modify the original suggestion to mark it metered.
+ networkSuggestion.wifiConfiguration.meteredOverride =
+ WifiConfiguration.METERED_OVERRIDE_METERED;
+
+ // Replace attempt should success.
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+ assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED,
+ mWifiNetworkSuggestionsManager
+ .get(TEST_PACKAGE_1).get(0).wifiConfiguration.meteredOverride);
+ // Verify we did not update config in WCM.
+ verify(mWifiConfigManager, never()).addOrUpdateNetwork(any(), anyInt(), any());
+ }
+
+ /**
+ * Verify that modify networks that are already active and is cached in WifiConfigManager is
+ * allowed and also updates the cache in WifiConfigManager.
+ */
+ @Test
+ public void testAddNetworkSuggestionsSuccessOnInPlaceModificationWhenInWcm() {
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, true);
+ List<WifiNetworkSuggestion> networkSuggestionList1 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ }};
+
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+
+ // Assert that the original config was not metered.
+ assertEquals(WifiConfiguration.METERED_OVERRIDE_NONE,
+ networkSuggestion.wifiConfiguration.meteredOverride);
+
+ // Store the original WifiConfiguration from WifiConfigManager.
+ WifiConfiguration configInWcm =
+ new WifiConfiguration(networkSuggestion.wifiConfiguration);
+ configInWcm.creatorUid = TEST_UID_1;
+ configInWcm.creatorName = TEST_PACKAGE_1;
+ configInWcm.fromWifiNetworkSuggestion = true;
+ setupGetConfiguredNetworksFromWcm(configInWcm);
+
+ // Modify the original suggestion to mark it metered.
networkSuggestion.wifiConfiguration.meteredOverride =
WifiConfiguration.METERED_OVERRIDE_METERED;
+ when(mWifiConfigManager.addOrUpdateNetwork(any(), eq(TEST_UID_1), eq(TEST_PACKAGE_1)))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
// Replace attempt should success.
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
@@ -539,6 +594,15 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED,
mWifiNetworkSuggestionsManager
.get(TEST_PACKAGE_1).get(0).wifiConfiguration.meteredOverride);
+
+ // Verify we did update config in WCM.
+ ArgumentCaptor<WifiConfiguration> configCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+ verify(mWifiConfigManager).addOrUpdateNetwork(
+ configCaptor.capture(), eq(TEST_UID_1), eq(TEST_PACKAGE_1));
+ assertNotNull(configCaptor.getValue());
+ assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED,
+ configCaptor.getValue().meteredOverride);
}
/**
@@ -3004,11 +3068,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
add(networkSuggestion2);
add(networkSuggestion3);
}};
- setupAddToWifiConfigManager(networkSuggestion1.wifiConfiguration,
- networkSuggestion2.wifiConfiguration, networkSuggestion3.wifiConfiguration);
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1, TEST_FEATURE));
+ setupGetConfiguredNetworksFromWcm(networkSuggestion1.wifiConfiguration,
+ networkSuggestion2.wifiConfiguration, networkSuggestion3.wifiConfiguration);
// When app is not approved, empty list will be returned
mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(false, TEST_PACKAGE_1);
List<WifiConfiguration> wifiConfigurationList = mWifiNetworkSuggestionsManager
@@ -3029,20 +3093,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(expectedSuggestions, actualSuggestions);
}
- private void setupAddToWifiConfigManager(WifiConfiguration...configs) {
+ private void setupGetConfiguredNetworksFromWcm(WifiConfiguration...configs) {
for (int i = 0; i < configs.length; i++) {
WifiConfiguration config = configs[i];
- config.fromWifiNetworkSuggestion = true;
- config.ephemeral = true;
- // setup & verify the WifiConfigmanager interactions for adding/enabling the network.
- when(mWifiConfigManager.addOrUpdateNetwork(
- eq(config), anyInt(), anyString()))
- .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID + i));
- when(mWifiConfigManager.updateNetworkSelectionStatus(eq(TEST_NETWORK_ID + i), anyInt()))
- .thenReturn(true);
- config.networkId = TEST_NETWORK_ID + i;
- when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID + i))
- .thenReturn(config);
when(mWifiConfigManager.getConfiguredNetwork(config.getKey())).thenReturn(config);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
index 98dbcb97a..3f92809dd 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -32,6 +32,7 @@ import static android.net.wifi.WifiManager.EXTRA_SUBSCRIPTION_REMEDIATION_METHOD
import static android.net.wifi.WifiManager.EXTRA_URL;
import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_EAP;
+import static com.android.server.wifi.WifiConfigurationTestUtil.TEST_NETWORK_ID;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
@@ -39,6 +40,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
@@ -88,6 +90,7 @@ import com.android.server.wifi.ClientModeImpl;
import com.android.server.wifi.Clock;
import com.android.server.wifi.FakeKeys;
import com.android.server.wifi.FrameworkFacade;
+import com.android.server.wifi.NetworkUpdateResult;
import com.android.server.wifi.WifiBaseTest;
import com.android.server.wifi.WifiConfigManager;
import com.android.server.wifi.WifiConfigStore;
@@ -887,6 +890,27 @@ public class PasspointManagerTest extends WifiBaseTest {
assertEquals(origConfig, origProviders.get(0).getConfig());
assertEquals(1, mSharedDataSource.getProviderIndex());
+ // Add same provider as existing suggestion provider
+ // This should be no WifiConfig deletion
+ WifiConfiguration origWifiConfig = origProvider.getWifiConfig();
+ when(mWifiConfigManager.getConfiguredNetwork(origWifiConfig.getKey()))
+ .thenReturn(origWifiConfig);
+ when(mWifiConfigManager.addOrUpdateNetwork(
+ origWifiConfig, TEST_CREATOR_UID, TEST_PACKAGE))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
+ assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE,
+ false, true));
+ verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork(
+ origWifiConfig.getKey());
+ verify(mWifiConfigManager).addOrUpdateNetwork(
+ argThat((c) -> c.FQDN.equals(TEST_FQDN)), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE));
+ verify(mWifiConfigManager).saveToStore(true);
+ verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
+ verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess();
+ assertEquals(2, mSharedDataSource.getProviderIndex());
+ reset(mWifiMetrics);
+ reset(mWifiConfigManager);
+
// Add another provider with the same base domain as the existing provider.
// This should replace the existing provider with the new configuration.
PasspointConfiguration newConfig = createTestConfigWithUserCredential(TEST_FQDN,
@@ -895,6 +919,8 @@ public class PasspointManagerTest extends WifiBaseTest {
when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore),
eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(newProvider);
+ when(mWifiConfigManager.getConfiguredNetwork(origProvider.getWifiConfig().getKey()))
+ .thenReturn(origWifiConfig);
assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE,
false, true));
@@ -913,7 +939,7 @@ public class PasspointManagerTest extends WifiBaseTest {
assertEquals(2, newProviders.size());
assertTrue(newConfig.equals(newProviders.get(0).getConfig())
|| newConfig.equals(newProviders.get(1).getConfig()));
- assertEquals(2, mSharedDataSource.getProviderIndex());
+ assertEquals(3, mSharedDataSource.getProviderIndex());
}
/**
@@ -2064,10 +2090,21 @@ public class PasspointManagerTest extends WifiBaseTest {
// Add same provider as existing suggestion provider
// This should be no WifiConfig deletion
+ WifiConfiguration origWifiConfig = origProvider.getWifiConfig();
+ origWifiConfig.fromWifiNetworkSuggestion = true;
+ origWifiConfig.creatorUid = TEST_CREATOR_UID;
+ origWifiConfig.creatorName = TEST_PACKAGE;
+ when(mWifiConfigManager.getConfiguredNetwork(origWifiConfig.getKey()))
+ .thenReturn(origWifiConfig);
+ when(mWifiConfigManager.addOrUpdateNetwork(
+ origWifiConfig, TEST_CREATOR_UID, TEST_PACKAGE))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE,
true, true));
verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork(
- origProvider.getWifiConfig().getKey());
+ origWifiConfig.getKey());
+ verify(mWifiConfigManager).addOrUpdateNetwork(
+ argThat((c) -> c.FQDN.equals(TEST_FQDN)), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE));
verify(mWifiConfigManager).saveToStore(true);
verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess();