summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-02-10 17:49:45 -0800
committerRoshan Pius <rpius@google.com>2017-02-14 12:08:39 -0800
commitc7a4b6706fa09042bb36a64036d86d88eb6e4126 (patch)
tree4c8b2c6937bb6d57f96206dacf987aed84b74ef3 /tests
parent7c0ec884188660f72977c8a80366049705c48ffa (diff)
SupplicantStaNetworkHal: Add FT flags
This is a port of the existing logic in WifiSupplicantControl. Need to add the FT flags when adding the network to wpa_supplicant when the device supports it (specified in device config.xml). Changed the input arguments to SupplicantStaNetworkHal & SupplicantStaIfaceHal so that it takes an instance of the Context and use WifiMonitor to trigger callbacks instead of directly sending events using WifiStateMachine handler. Bug: 33383725 Test: Unit tests Change-Id: Id266835ef5dc3038057cab5b8f8da3a327f39ce2
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java68
2 files changed, 67 insertions, 18 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index 52d5a28c3..a0caad09d 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.test.MockAnswerUtil;
+import android.content.Context;
import android.hardware.wifi.supplicant.V1_0.ISupplicant;
import android.hardware.wifi.supplicant.V1_0.ISupplicantIface;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface;
@@ -42,10 +43,8 @@ import android.hidl.manager.V1_0.IServiceManager;
import android.hidl.manager.V1_0.IServiceNotification;
import android.net.IpConfiguration;
import android.net.wifi.WifiConfiguration;
-import android.os.HandlerThread;
import android.os.IHwBinder;
import android.os.RemoteException;
-import android.os.test.TestLooper;
import android.util.SparseArray;
import org.junit.Before;
@@ -77,7 +76,8 @@ public class SupplicantStaIfaceHalTest {
@Mock ISupplicant mISupplicantMock;
@Mock ISupplicantIface mISupplicantIfaceMock;
@Mock ISupplicantStaIface mISupplicantStaIfaceMock;
- @Mock HandlerThread mHandlerThread;
+ @Mock Context mContext;
+ @Mock WifiMonitor mWifiMonitor;
@Mock SupplicantStaNetworkHal mSupplicantStaNetworkMock;
SupplicantStatus mStatusSuccess;
SupplicantStatus mStatusFailure;
@@ -89,12 +89,11 @@ public class SupplicantStaIfaceHalTest {
ArgumentCaptor.forClass(IHwBinder.DeathRecipient.class);
private ArgumentCaptor<IServiceNotification.Stub> mServiceNotificationCaptor =
ArgumentCaptor.forClass(IServiceNotification.Stub.class);
- private TestLooper mTestLooper;
private InOrder mInOrder;
private class SupplicantStaIfaceHalSpy extends SupplicantStaIfaceHal {
- SupplicantStaIfaceHalSpy(HandlerThread handlerThread) {
- super(handlerThread);
+ SupplicantStaIfaceHalSpy(Context context, WifiMonitor monitor) {
+ super(context, monitor);
}
@Override
@@ -114,7 +113,7 @@ public class SupplicantStaIfaceHalTest {
@Override
protected SupplicantStaNetworkHal getStaNetworkMockable(
- ISupplicantStaNetwork iSupplicantStaNetwork, HandlerThread handlerThread) {
+ ISupplicantStaNetwork iSupplicantStaNetwork) {
return mSupplicantStaNetworkMock;
}
}
@@ -122,7 +121,6 @@ public class SupplicantStaIfaceHalTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mTestLooper = new TestLooper();
mStatusSuccess = createSupplicantStatus(SupplicantStatusCode.SUCCESS);
mStatusFailure = createSupplicantStatus(SupplicantStatusCode.FAILURE_UNKNOWN);
mStaIface = createIfaceInfo(IfaceType.STA, "wlan0");
@@ -136,8 +134,7 @@ public class SupplicantStaIfaceHalTest {
anyLong())).thenReturn(true);
when(mServiceManagerMock.registerForNotifications(anyString(), anyString(),
any(IServiceNotification.Stub.class))).thenReturn(true);
- when(mHandlerThread.getLooper()).thenReturn(mTestLooper.getLooper());
- mDut = new SupplicantStaIfaceHalSpy(mHandlerThread);
+ mDut = new SupplicantStaIfaceHalSpy(mContext, mWifiMonitor);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
index dc598662a..6021b1c7d 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
@@ -21,17 +21,17 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
import android.app.test.MockAnswerUtil.AnswerWithArguments;
+import android.content.Context;
import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
-import android.os.HandlerThread;
import android.os.RemoteException;
-import android.os.test.TestLooper;
import android.text.TextUtils;
+import com.android.internal.R;
import com.android.server.wifi.util.NativeUtil;
import org.junit.Before;
@@ -53,22 +53,22 @@ public class SupplicantStaNetworkHalTest {
private SupplicantStatus mStatusSuccess;
private SupplicantStatus mStatusFailure;
@Mock private ISupplicantStaNetwork mISupplicantStaNetworkMock;
- @Mock private HandlerThread mHandlerThread;
- private TestLooper mTestLooper;
+ @Mock private Context mContext;
+ @Mock private WifiMonitor mWifiMonitor;
private SupplicantNetworkVariables mSupplicantVariables;
+ private MockResources mResources;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mTestLooper = new TestLooper();
mStatusSuccess = createSupplicantStatus(SupplicantStatusCode.SUCCESS);
mStatusFailure = createSupplicantStatus(SupplicantStatusCode.FAILURE_UNKNOWN);
- when(mHandlerThread.getLooper()).thenReturn(mTestLooper.getLooper());
mSupplicantVariables = new SupplicantNetworkVariables();
setupISupplicantNetworkMock();
- mSupplicantNetwork =
- new SupplicantStaNetworkHal(mISupplicantStaNetworkMock, mHandlerThread);
+ mResources = new MockResources();
+ when(mContext.getResources()).thenReturn(mResources);
+ createSupplicantStaNetwork();
}
/**
@@ -545,6 +545,50 @@ public class SupplicantStaNetworkHalTest {
assertTrue(mSupplicantNetwork.sendNetworkEapIdentityResponse(identityStr));
}
+ /**
+ * Tests the addition of FT flags when the device supports it.
+ */
+ @Test
+ public void testAddFtPskFlags() throws Exception {
+ mResources.setBoolean(R.bool.config_wifi_fast_bss_transition_enabled, true);
+ createSupplicantStaNetwork();
+
+ WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
+ assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
+
+ // Check the supplicant variables to ensure that we have added the FT flags.
+ assertTrue((mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.FT_PSK)
+ == ISupplicantStaNetwork.KeyMgmtMask.FT_PSK);
+
+ WifiConfiguration loadConfig = new WifiConfiguration();
+ Map<String, String> networkExtras = new HashMap<>();
+ assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras));
+ // The FT flags should be stripped out when reading it back.
+ WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig);
+ }
+
+ /**
+ * Tests the addition of FT flags when the device supports it.
+ */
+ @Test
+ public void testAddFtEapFlags() throws Exception {
+ mResources.setBoolean(R.bool.config_wifi_fast_bss_transition_enabled, true);
+ createSupplicantStaNetwork();
+
+ WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork();
+ assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
+
+ // Check the supplicant variables to ensure that we have added the FT flags.
+ assertTrue((mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.FT_EAP)
+ == ISupplicantStaNetwork.KeyMgmtMask.FT_EAP);
+
+ WifiConfiguration loadConfig = new WifiConfiguration();
+ Map<String, String> networkExtras = new HashMap<>();
+ assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras));
+ // The FT flags should be stripped out when reading it back.
+ WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig);
+ }
+
private void testWifiConfigurationSaveLoad(WifiConfiguration config) {
assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
WifiConfiguration loadConfig = new WifiConfiguration();
@@ -1018,6 +1062,14 @@ public class SupplicantStaNetworkHalTest {
return status;
}
+ /**
+ * Need this for tests which wants to manipulate context before creating the instance.
+ */
+ private void createSupplicantStaNetwork() {
+ mSupplicantNetwork =
+ new SupplicantStaNetworkHal(mISupplicantStaNetworkMock, mContext, mWifiMonitor);
+ }
+
// Private class to to store/inspect values set via the HIDL mock.
private class SupplicantNetworkVariables {
public ArrayList<Byte> ssid;