summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2017-02-24 14:12:00 -0800
committerPeter Qiu <zqiu@google.com>2017-03-02 14:12:21 -0800
commitdd97694345f47ba6a952c1162e7dcdd66fb72060 (patch)
tree96e0a18a8f288e4f29df904971eabd65a06807fe /tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
parent040829fe448045d12cbc90f6143aca7da6b5aa80 (diff)
downloadandroid_frameworks_opt_net_wifi-dd97694345f47ba6a952c1162e7dcdd66fb72060.tar.gz
android_frameworks_opt_net_wifi-dd97694345f47ba6a952c1162e7dcdd66fb72060.tar.bz2
android_frameworks_opt_net_wifi-dd97694345f47ba6a952c1162e7dcdd66fb72060.zip
hotspot2: synchronize Passpoint configuration changes through WifiStateMachine
This is to avoid any race conditions so that all Passpoint configuration changes and use of those configurations will be done in the WifiStateMachine thread. While there, initiate a disconnect when removing a Passpoint provider and the current connecting/connected network is provided by that provider. Bug: 33200134, 34202139 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: manually remove the Global Reach Passpoint profile while the phone is connected to its network, verified that the profile is removed and the WiFi connection is torn down Change-Id: I88feac77d3c1c1836d651df09d01142b73489c54
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 669c9fded..45874ac80 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -17,6 +17,7 @@
package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
@@ -42,6 +43,8 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiScanner;
import android.net.wifi.WifiSsid;
+import android.net.wifi.hotspot2.PasspointConfiguration;
+import android.net.wifi.hotspot2.pps.HomeSp;
import android.net.wifi.p2p.IWifiP2pManager;
import android.os.BatteryStats;
import android.os.Binder;
@@ -73,6 +76,7 @@ import com.android.internal.util.AsyncChannel;
import com.android.internal.util.IState;
import com.android.internal.util.StateMachine;
import com.android.server.wifi.hotspot2.NetworkDetail;
+import com.android.server.wifi.hotspot2.PasspointManager;
import com.android.server.wifi.p2p.WifiP2pServiceImpl;
import org.junit.After;
@@ -324,6 +328,7 @@ public class WifiStateMachineTest {
@Mock WifiConnectivityManager mWifiConnectivityManager;
@Mock SoftApManager mSoftApManager;
@Mock WifiStateTracker mWifiStateTracker;
+ @Mock PasspointManager mPasspointManager;
public WifiStateMachineTest() throws Exception {
}
@@ -360,6 +365,7 @@ public class WifiStateMachineTest {
any(SoftApManager.Listener.class), any(IApInterface.class),
any(WifiConfiguration.class)))
.thenReturn(mSoftApManager);
+ when(mWifiInjector.getPasspointManager()).thenReturn(mPasspointManager);
when(mWifiNative.setupDriverForClientMode()).thenReturn(mClientInterface);
when(mWifiNative.setupDriverForSoftApMode()).thenReturn(mApInterface);
@@ -1089,4 +1095,82 @@ public class WifiStateMachineTest {
assertEquals(featureInfra,
testGetSupportedFeaturesCase(featureInfra | featureD2dRtt | featureD2apRtt, true));
}
+
+ /**
+ * Verify that syncAddOrUpdatePasspointConfig will redirect calls to {@link PasspointManager}
+ * and returning the result that's returned from {@link PasspointManager}.
+ */
+ @Test
+ public void syncAddOrUpdatePasspointConfig() throws Exception {
+ when(mPasspointManager.addOrUpdateProvider(any(PasspointConfiguration.class)))
+ .thenReturn(true);
+ mLooper.startAutoDispatch();
+ assertTrue(mWsm.syncAddOrUpdatePasspointConfig(mWsmAsyncChannel,
+ new PasspointConfiguration()));
+ mLooper.stopAutoDispatch();
+ reset(mPasspointManager);
+
+ when(mPasspointManager.addOrUpdateProvider(any(PasspointConfiguration.class)))
+ .thenReturn(false);
+ mLooper.startAutoDispatch();
+ assertFalse(mWsm.syncAddOrUpdatePasspointConfig(mWsmAsyncChannel,
+ new PasspointConfiguration()));
+ mLooper.stopAutoDispatch();
+ }
+
+ /**
+ * Verify that syncRemovePasspointConfig will redirect calls to {@link PasspointManager}
+ * and returning the result that's returned from {@link PasspointManager}.
+ */
+ @Test
+ public void syncRemovePasspointConfig() throws Exception {
+ String fqdn = "test.com";
+ when(mPasspointManager.removeProvider(fqdn)).thenReturn(true);
+ mLooper.startAutoDispatch();
+ assertTrue(mWsm.syncRemovePasspointConfig(mWsmAsyncChannel, fqdn));
+ mLooper.stopAutoDispatch();
+ reset(mPasspointManager);
+
+ when(mPasspointManager.removeProvider(fqdn)).thenReturn(false);
+ mLooper.startAutoDispatch();
+ assertFalse(mWsm.syncRemovePasspointConfig(mWsmAsyncChannel, fqdn));
+ mLooper.stopAutoDispatch();
+ }
+
+ /**
+ * Verify that syncRemovePasspointConfig will redirect calls to {@link PasspointManager}
+ * and returning the result that's returned from {@link PasspointManager} when in client mode.
+ */
+ @Test
+ public void syncRemovePasspointConfigInClientMode() throws Exception {
+ loadComponentsInStaMode();
+ syncRemovePasspointConfig();
+ }
+
+ /**
+ * Verify that syncGetPasspointConfigs will redirect calls to {@link PasspointManager}
+ * and returning the result that's returned from {@link PasspointManager}.
+ */
+ @Test
+ public void syncGetPasspointConfigs() throws Exception {
+ // Setup expected configs.
+ List<PasspointConfiguration> expectedConfigs = new ArrayList<>();
+ PasspointConfiguration config = new PasspointConfiguration();
+ HomeSp homeSp = new HomeSp();
+ homeSp.setFqdn("test.com");
+ config.setHomeSp(homeSp);
+ expectedConfigs.add(config);
+
+ when(mPasspointManager.getProviderConfigs()).thenReturn(expectedConfigs);
+ mLooper.startAutoDispatch();
+ assertEquals(expectedConfigs, mWsm.syncGetPasspointConfigs(mWsmAsyncChannel));
+ mLooper.stopAutoDispatch();
+ reset(mPasspointManager);
+
+ when(mPasspointManager.getProviderConfigs())
+ .thenReturn(new ArrayList<PasspointConfiguration>());
+ mLooper.startAutoDispatch();
+ assertTrue(mWsm.syncGetPasspointConfigs(mWsmAsyncChannel).isEmpty());
+ mLooper.stopAutoDispatch();
+ }
}