summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-06-07 21:09:25 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-06-07 21:09:25 +0000
commit854d0e5f85b7190169d5268e675700fa7a6a50cb (patch)
treeb14ae11a0356349f90b11fb9cd996c3ec97eaaf5 /tests
parente1055545555a04076c14daf976a5e476ed8ce631 (diff)
parentdea3f9fb315088dba8f6f5830b5c1917d5d29054 (diff)
Merge "WifiStateMachine: add mode to softap update" into oc-dev
am: dea3f9fb31 Change-Id: I5970aceb5e878ad43e43fa0cae34d415a1ff5f40
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/TestUtil.java12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java78
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java34
3 files changed, 82 insertions, 42 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/TestUtil.java b/tests/wifitests/src/com/android/server/wifi/TestUtil.java
index 8ff33b4cd..a0a103026 100644
--- a/tests/wifitests/src/com/android/server/wifi/TestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/TestUtil.java
@@ -74,15 +74,8 @@ public class TestUtil {
* Send {@link WifiManager#WIFI_AP_STATE_CHANGED} broadcast.
*/
public static void sendWifiApStateChanged(BroadcastReceiver broadcastReceiver,
- Context context, int apState, int previousState, int error) {
- sendWifiApStateChanged(broadcastReceiver, context, apState, previousState, error, null);
- }
-
- /**
- * Send {@link WifiManager#WIFI_AP_STATE_CHANGED} broadcast.
- */
- public static void sendWifiApStateChanged(BroadcastReceiver broadcastReceiver,
- Context context, int apState, int previousState, int error, String ifaceName) {
+ Context context, int apState, int previousState, int error, String ifaceName,
+ int mode) {
Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, apState);
intent.putExtra(WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE, previousState);
@@ -91,6 +84,7 @@ public class TestUtil {
intent.putExtra(WifiManager.EXTRA_WIFI_AP_FAILURE_REASON, error);
}
intent.putExtra(WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME, ifaceName);
+ intent.putExtra(WifiManager.EXTRA_WIFI_AP_MODE, mode);
broadcastReceiver.onReceive(context, intent);
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 36c4d9364..562143335 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -132,6 +132,8 @@ public class WifiServiceImplTest {
ArgumentCaptor.forClass(IntentFilter.class);
final ArgumentCaptor<Message> mMessageCaptor = ArgumentCaptor.forClass(Message.class);
+ final ArgumentCaptor<SoftApModeConfiguration> mSoftApModeConfigCaptor =
+ ArgumentCaptor.forClass(SoftApModeConfiguration.class);
@Mock Context mContext;
@Mock WifiInjector mWifiInjector;
@@ -534,7 +536,9 @@ public class WifiServiceImplTest {
when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_TETHERING)))
.thenReturn(false);
mWifiServiceImpl.setWifiApEnabled(null, true);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(null));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -549,7 +553,9 @@ public class WifiServiceImplTest {
.thenReturn(false);
WifiConfiguration apConfig = new WifiConfiguration();
mWifiServiceImpl.setWifiApEnabled(apConfig, true);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(apConfig));
+ verify(mWifiController).sendMessage(
+ eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertEquals(apConfig, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -562,7 +568,9 @@ public class WifiServiceImplTest {
when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_TETHERING)))
.thenReturn(false);
mWifiServiceImpl.setWifiApEnabled(null, false);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(0), eq(0), eq(null));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(0), eq(0), mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -576,7 +584,8 @@ public class WifiServiceImplTest {
// mApConfig is a mock and the values are not set - triggering the invalid config. Testing
// will be improved when we actually do test softap configs in b/37280779
mWifiServiceImpl.setWifiApEnabled(mApConfig, true);
- verify(mWifiController, never()).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(mApConfig));
+ verify(mWifiController, never())
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), any(SoftApModeConfiguration.class));
}
/**
@@ -613,7 +622,9 @@ public class WifiServiceImplTest {
public void testStartSoftApWithPermissionsAndNullConfig() {
boolean result = mWifiServiceImpl.startSoftAp(null);
assertTrue(result);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(null));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -634,7 +645,9 @@ public class WifiServiceImplTest {
WifiConfiguration config = new WifiConfiguration();
boolean result = mWifiServiceImpl.startSoftAp(config);
assertTrue(result);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(config));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertEquals(config, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -874,7 +887,7 @@ public class WifiServiceImplTest {
public void testStopLocalOnlyHotspotTriggersSoftApStopWithOneRegisteredRequest() {
registerLOHSRequestFull();
verify(mWifiController)
- .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), any(WifiConfiguration.class));
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), any(SoftApModeConfiguration.class));
mWifiServiceImpl.stopLocalOnlyHotspot();
// there is was only one request registered, we should tear down softap
@@ -957,7 +970,8 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_GENERAL);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_GENERAL,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
Message message = mMessageCaptor.getValue();
@@ -981,7 +995,8 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_NO_CHANNEL);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_NO_CHANNEL,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1013,7 +1028,8 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1045,7 +1061,8 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1069,7 +1086,8 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME);
+ WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME,
+ IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verifyNoMoreInteractions(mHandler);
@@ -1099,9 +1117,11 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1125,9 +1145,11 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1155,9 +1177,11 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
verify(mRequestInfo).sendHotspotFailedMessage(ERROR_GENERIC);
mLooper.dispatchAll();
@@ -1194,9 +1218,11 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
verify(mRequestInfo).sendHotspotStoppedMessage();
mLooper.dispatchAll();
@@ -1223,9 +1249,11 @@ public class WifiServiceImplTest {
mWifiServiceImpl.registerLOHSForTest(TEST_PID2, mRequestInfo2);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
verify(mRequestInfo).sendHotspotFailedMessage(ERROR_GENERIC);
verify(mRequestInfo2).sendHotspotFailedMessage(ERROR_GENERIC);
@@ -1383,9 +1411,11 @@ public class WifiServiceImplTest {
// now stop the hotspot
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
assertEquals(HOTSPOT_STOPPED, mMessageCaptor.getValue().what);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 86bf62fe5..2a30b671b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -19,6 +19,7 @@ package com.android.server.wifi;
import static android.net.wifi.WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_FAILURE_REASON;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLING;
@@ -495,20 +496,23 @@ public class WifiStateMachineTest {
}
private void checkApStateChangedBroadcast(Intent intent, int expectedCurrentState,
- int expectedPrevState, int expectedErrorCode, String expectedIfaceName) {
+ int expectedPrevState, int expectedErrorCode, String expectedIfaceName,
+ int expectedMode) {
int currentState = intent.getIntExtra(EXTRA_WIFI_AP_STATE, WIFI_AP_STATE_DISABLED);
int prevState = intent.getIntExtra(EXTRA_PREVIOUS_WIFI_AP_STATE, WIFI_AP_STATE_DISABLED);
int errorCode = intent.getIntExtra(EXTRA_WIFI_AP_FAILURE_REASON, HOTSPOT_NO_ERROR);
String ifaceName = intent.getStringExtra(EXTRA_WIFI_AP_INTERFACE_NAME);
+ int mode = intent.getIntExtra(EXTRA_WIFI_AP_MODE, WifiManager.IFACE_IP_MODE_UNSPECIFIED);
assertEquals(expectedCurrentState, currentState);
assertEquals(expectedPrevState, prevState);
assertEquals(expectedErrorCode, errorCode);
assertEquals(expectedIfaceName, ifaceName);
+ assertEquals(expectedMode, mode);
}
- @Test
- public void loadComponentsInApMode() throws Exception {
- mWsm.setHostApRunning(new WifiConfiguration(), true);
+ private void loadComponentsInApMode(int mode) throws Exception {
+ SoftApModeConfiguration config = new SoftApModeConfiguration(mode, new WifiConfiguration());
+ mWsm.setHostApRunning(config, true);
mLooper.dispatchAll();
assertEquals("SoftApState", getCurrentState().getName());
@@ -532,13 +536,23 @@ public class WifiStateMachineTest {
List<Intent> capturedIntents = intentCaptor.getAllValues();
checkApStateChangedBroadcast(capturedIntents.get(0), WIFI_AP_STATE_ENABLING,
- WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME);
+ WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
checkApStateChangedBroadcast(capturedIntents.get(1), WIFI_AP_STATE_ENABLED,
- WIFI_AP_STATE_ENABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME);
+ WIFI_AP_STATE_ENABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
checkApStateChangedBroadcast(capturedIntents.get(2), WIFI_AP_STATE_DISABLING,
- WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME);
+ WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
checkApStateChangedBroadcast(capturedIntents.get(3), WIFI_AP_STATE_DISABLED,
- WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME);
+ WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
+ }
+
+ @Test
+ public void loadComponentsInApModeForTethering() throws Exception {
+ loadComponentsInApMode(WifiManager.IFACE_IP_MODE_TETHERED);
+ }
+
+ @Test
+ public void loadComponentsInApModeForLOHS() throws Exception {
+ loadComponentsInApMode(WifiManager.IFACE_IP_MODE_LOCAL_ONLY);
}
@Test
@@ -662,7 +676,9 @@ public class WifiStateMachineTest {
mWsm.setSupplicantRunning(false);
mWsm.sendMessage(WifiStateMachine.CMD_DISABLE_P2P_RSP);
mWsm.sendMessage(WifiMonitor.SUP_DISCONNECTION_EVENT);
- mWsm.setHostApRunning(new WifiConfiguration(), true);
+ SoftApModeConfiguration config = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, new WifiConfiguration());
+ mWsm.setHostApRunning(config, true);
mLooper.dispatchAll();
assertEquals("SoftApState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());