diff options
author | Rebecca Silberstein <silberst@google.com> | 2017-06-06 18:59:34 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-06-06 18:59:34 +0000 |
commit | 1e34b97fcfdc4c78817f15985a168f279b100afa (patch) | |
tree | 72eda725b048928b451ced092d2c36dea84c798a /tests | |
parent | cbcfdbfcb8be58d6bcb0e4e486ef01ac0116799b (diff) | |
parent | 70126fea6716aa051d433306ebababb6fe3a45d5 (diff) |
Merge "WifiStateMachine: add iface name to ap updates" into oc-dev
am: 70126fea67
Change-Id: I3b2c8050b8ddcb035194853861a679b7f4017adb
Diffstat (limited to 'tests')
3 files changed, 67 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/TestUtil.java b/tests/wifitests/src/com/android/server/wifi/TestUtil.java index 90df07a61..8ff33b4cd 100644 --- a/tests/wifitests/src/com/android/server/wifi/TestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/TestUtil.java @@ -75,13 +75,23 @@ public class TestUtil { */ 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) { 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); if (apState == WifiManager.WIFI_AP_STATE_FAILED) { - //only set reason number when softAP start failed + // only set reason number when softAP start failed intent.putExtra(WifiManager.EXTRA_WIFI_AP_FAILURE_REASON, error); } + intent.putExtra(WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME, ifaceName); + 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 7342cdb16..36c4d9364 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -1069,7 +1069,7 @@ public class WifiServiceImplTest { registerLOHSRequestFull(); TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext, - WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR); + WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME); mLooper.dispatchAll(); verifyNoMoreInteractions(mHandler); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index be9b0c544..86bf62fe5 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -16,6 +16,17 @@ 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_STATE; +import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; +import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLING; +import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED; +import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLING; + +import static com.android.server.wifi.LocalOnlyHotspotRequestInfo.HOTSPOT_NO_ERROR; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -303,6 +314,7 @@ public class WifiStateMachineTest { static final String sHexSSID = sWifiSsid.getHexString().replace("0x", "").replace("22", ""); static final String sBSSID = "01:02:03:04:05:06"; static final int sFreq = 2437; + static final String WIFI_IFACE_NAME = "mockWlan"; WifiStateMachine mWsm; HandlerThread mWsmThread; @@ -315,6 +327,9 @@ public class WifiStateMachineTest { TestLooper mLooper; Context mContext; + final ArgumentCaptor<SoftApManager.Listener> mSoftApManagerListenerCaptor = + ArgumentCaptor.forClass(SoftApManager.Listener.class); + @Mock WifiScanner mWifiScanner; @Mock SupplicantStateTracker mSupplicantStateTracker; @Mock WifiMetrics mWifiMetrics; @@ -370,7 +385,7 @@ public class WifiStateMachineTest { when(mWifiInjector.makeWifiConnectivityManager(any(WifiInfo.class), anyBoolean())) .thenReturn(mWifiConnectivityManager); when(mWifiInjector.makeSoftApManager(any(INetworkManagementService.class), - any(SoftApManager.Listener.class), any(IApInterface.class), + mSoftApManagerListenerCaptor.capture(), any(IApInterface.class), any(WifiConfiguration.class))) .thenReturn(mSoftApManager); when(mWifiInjector.getPasspointManager()).thenReturn(mPasspointManager); @@ -381,7 +396,8 @@ public class WifiStateMachineTest { when(mWifiNative.setupForClientMode()).thenReturn(mClientInterface); when(mWifiNative.setupForSoftApMode()).thenReturn(mApInterface); - when(mWifiNative.getInterfaceName()).thenReturn("mockWlan"); + when(mApInterface.getInterfaceName()).thenReturn(WIFI_IFACE_NAME); + when(mWifiNative.getInterfaceName()).thenReturn(WIFI_IFACE_NAME); when(mWifiNative.enableSupplicant()).thenReturn(true); when(mWifiNative.disableSupplicant()).thenReturn(true); when(mWifiNative.getFrameworkNetworkId(anyInt())).thenReturn(0); @@ -478,6 +494,18 @@ public class WifiStateMachineTest { assertEquals("DisconnectedState", getCurrentState().getName()); } + private void checkApStateChangedBroadcast(Intent intent, int expectedCurrentState, + int expectedPrevState, int expectedErrorCode, String expectedIfaceName) { + 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); + assertEquals(expectedCurrentState, currentState); + assertEquals(expectedPrevState, prevState); + assertEquals(expectedErrorCode, errorCode); + assertEquals(expectedIfaceName, ifaceName); + } + @Test public void loadComponentsInApMode() throws Exception { mWsm.setHostApRunning(new WifiConfiguration(), true); @@ -486,6 +514,31 @@ public class WifiStateMachineTest { assertEquals("SoftApState", getCurrentState().getName()); verify(mSoftApManager).start(); + + // reset expectations for mContext due to previously sent AP broadcast + reset(mContext); + + // get the SoftApManager.Listener and trigger some updates + SoftApManager.Listener listener = mSoftApManagerListenerCaptor.getValue(); + listener.onStateChanged(WIFI_AP_STATE_ENABLING, 0); + listener.onStateChanged(WIFI_AP_STATE_ENABLED, 0); + listener.onStateChanged(WIFI_AP_STATE_DISABLING, 0); + // note, this will trigger a mode change when TestLooper is dispatched + listener.onStateChanged(WIFI_AP_STATE_DISABLED, 0); + + ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(mContext, times(4)) + .sendStickyBroadcastAsUser(intentCaptor.capture(), eq(UserHandle.ALL)); + + List<Intent> capturedIntents = intentCaptor.getAllValues(); + checkApStateChangedBroadcast(capturedIntents.get(0), WIFI_AP_STATE_ENABLING, + WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME); + checkApStateChangedBroadcast(capturedIntents.get(1), WIFI_AP_STATE_ENABLED, + WIFI_AP_STATE_ENABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME); + checkApStateChangedBroadcast(capturedIntents.get(2), WIFI_AP_STATE_DISABLING, + WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME); + checkApStateChangedBroadcast(capturedIntents.get(3), WIFI_AP_STATE_DISABLED, + WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME); } @Test |