diff options
author | Les Lee <lesl@google.com> | 2019-11-06 05:18:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-11-06 05:18:26 +0000 |
commit | c80e77863c27765f1ca5879f00164f433acc6680 (patch) | |
tree | 3c4743cdb44a64690e90828bdffc8d06a3d38ef7 /tests | |
parent | 6526225524c46107b58d517066553333af2b13e1 (diff) | |
parent | 5b500059fb398517f62aabc7e52f02cfecba9276 (diff) |
Merge "wifi: Add SoftApInfo Callback support"
Diffstat (limited to 'tests')
3 files changed, 134 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java index 073ef4e3f..7d788c3d1 100644 --- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java @@ -45,6 +45,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.location.LocationManager; +import android.net.wifi.SoftApInfo; import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; @@ -87,6 +88,8 @@ public class ActiveModeWardenTest extends WifiBaseTest { private static final String WIFI_IFACE_NAME = "mockWlan"; private static final int TEST_WIFI_RECOVERY_DELAY_MS = 2000; + private static final int TEST_AP_FREQUENCY = 2412; + private static final int TEST_AP_BANDWIDTH = SoftApInfo.CHANNEL_WIDTH_20MHZ; TestLooper mLooper; @Mock WifiInjector mWifiInjector; @@ -114,6 +117,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { @Mock WifiManager.SoftApCallback mLohsStateMachineCallback; WifiNative.StatusListener mWifiNativeStatusListener; ActiveModeWarden mActiveModeWarden; + private SoftApInfo mTestSoftApInfo; final ArgumentCaptor<WifiNative.StatusListener> mStatusListenerCaptor = ArgumentCaptor.forClass(WifiNative.StatusListener.class); @@ -170,6 +174,9 @@ public class ActiveModeWardenTest extends WifiBaseTest { mActiveModeWarden.registerSoftApCallback(mSoftApStateMachineCallback); mActiveModeWarden.registerLohsCallback(mLohsStateMachineCallback); + mTestSoftApInfo = new SoftApInfo(); + mTestSoftApInfo.setFrequency(TEST_AP_FREQUENCY); + mTestSoftApInfo.setBandwidth(TEST_AP_BANDWIDTH); } private ActiveModeWarden createActiveModeWarden() { @@ -641,6 +648,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { verify(mSoftApStateMachineCallback, never()).onStateChanged(anyInt(), anyInt()); verify(mSoftApStateMachineCallback, never()).onConnectedClientsChanged(any()); + verify(mSoftApStateMachineCallback, never()).onInfoChanged(any()); } /** @@ -657,6 +665,18 @@ public class ActiveModeWardenTest extends WifiBaseTest { } /** + * Verifies that SoftApInfoChanged event is being passed from SoftApManager to WifiServiceImpl + */ + @Test + public void callsWifiServiceCallbackOnSoftApInfoChanged() throws Exception { + enterSoftApActiveMode(); + mSoftApManagerCallback.onInfoChanged(mTestSoftApInfo); + mLooper.dispatchAll(); + + verify(mSoftApStateMachineCallback).onInfoChanged(mTestSoftApInfo); + } + + /** * Test that we remain in the active state when we get a state change update that scan mode is * active. */ diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index 9fd36fbd9..a00c1bac6 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -54,6 +54,7 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.net.MacAddress; import android.net.Uri; +import android.net.wifi.SoftApInfo; import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; @@ -104,12 +105,17 @@ public class SoftApManagerTest extends WifiBaseTest { }; private static final List<NativeWifiClient> TEST_CONNECTED_NATIVECLIENTS = new ArrayList(Arrays.asList(TEST_NATIVE_CLIENT)); + private static final int TEST_AP_FREQUENCY = 2412; + private static final int TEST_AP_BANDWIDTH_FROM_IFACE_CALLBACK = + IApInterfaceEventCallback.BANDWIDTH_20; + private static final int TEST_AP_BANDWIDTH_IN_SOFTAPINFO = SoftApInfo.CHANNEL_WIDTH_20MHZ; private final WifiConfiguration mDefaultApConfig = createDefaultApConfig(); private ContentObserver mContentObserver; private TestLooper mLooper; private TestAlarmManager mAlarmManager; + private SoftApInfo mTestSoftApInfo; @Mock Context mContext; @Mock Resources mResources; @@ -150,6 +156,9 @@ public class SoftApManagerTest extends WifiBaseTest { when(mWifiNative.getFactoryMacAddress(any())).thenReturn(TEST_MAC_ADDRESS); when(mWifiApConfigStore.randomizeBssidIfUnset(any(), any())).thenAnswer( (invocation) -> invocation.getArgument(1)); + mTestSoftApInfo = new SoftApInfo(); + mTestSoftApInfo.setFrequency(TEST_AP_FREQUENCY); + mTestSoftApInfo.setBandwidth(TEST_AP_BANDWIDTH_IN_SOFTAPINFO); } private WifiConfiguration createDefaultApConfig() { @@ -885,6 +894,98 @@ public class SoftApManagerTest extends WifiBaseTest { verify(mWifiMetrics, never()).incrementNumSoftApUserBandPreferenceUnsatisfied(); } + /** + * If SoftApManager gets an update for the ap channal and the frequency, it will trigger + * callbacks to update softap information. + */ + @Test + public void testOnSoftApChannelSwitchedEventTriggerSoftApInfoUpdate() throws Exception { + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null); + startSoftApAndVerifyEnabled(apConfig); + + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched( + TEST_AP_FREQUENCY, TEST_AP_BANDWIDTH_FROM_IFACE_CALLBACK); + mLooper.dispatchAll(); + + verify(mCallback).onInfoChanged(mTestSoftApInfo); + verify(mWifiMetrics).addSoftApChannelSwitchedEvent(TEST_AP_FREQUENCY, + TEST_AP_BANDWIDTH_IN_SOFTAPINFO, apConfig.getTargetMode()); + } + + /** + * If SoftApManager gets an update for the ap channal and the frequency those are the same, + * do not trigger callbacks a second time. + */ + @Test + public void testDoesNotTriggerCallbackForSameChannelInfoUpdate() throws Exception { + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null); + startSoftApAndVerifyEnabled(apConfig); + + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched( + TEST_AP_FREQUENCY, TEST_AP_BANDWIDTH_FROM_IFACE_CALLBACK); + mLooper.dispatchAll(); + + // now trigger callback again, but we should have each method only called once + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched( + TEST_AP_FREQUENCY, TEST_AP_BANDWIDTH_FROM_IFACE_CALLBACK); + mLooper.dispatchAll(); + + verify(mCallback).onInfoChanged(mTestSoftApInfo); + verify(mWifiMetrics).addSoftApChannelSwitchedEvent(TEST_AP_FREQUENCY, + TEST_AP_BANDWIDTH_IN_SOFTAPINFO, apConfig.getTargetMode()); + } + + /** + * If SoftApManager gets an update for the invalid ap frequency, it will not + * trigger callbacks + */ + @Test + public void testHandlesInvalidChannelFrequency() throws Exception { + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null); + startSoftApAndVerifyEnabled(apConfig); + + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched( + -1, TEST_AP_BANDWIDTH_FROM_IFACE_CALLBACK); + mLooper.dispatchAll(); + + verify(mCallback, never()).onInfoChanged(any()); + verify(mWifiMetrics, never()).addSoftApChannelSwitchedEvent(anyInt(), anyInt(), + anyInt()); + } + + /** + * If softap leave started state, it should update softap inforation which frequency is 0 via + * trigger callbacks. + */ + @Test + public void testCallbackForChannelUpdateToZeroWhenLeaveSoftapStarted() throws Exception { + InOrder order = inOrder(mCallback, mWifiMetrics); + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null); + startSoftApAndVerifyEnabled(apConfig); + + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched( + TEST_AP_FREQUENCY, TEST_AP_BANDWIDTH_FROM_IFACE_CALLBACK); + mLooper.dispatchAll(); + + order.verify(mCallback).onInfoChanged(mTestSoftApInfo); + order.verify(mWifiMetrics).addSoftApChannelSwitchedEvent(TEST_AP_FREQUENCY, + TEST_AP_BANDWIDTH_IN_SOFTAPINFO, apConfig.getTargetMode()); + + mSoftApManager.stop(); + mLooper.dispatchAll(); + + mTestSoftApInfo.setFrequency(0); + mTestSoftApInfo.setBandwidth(SoftApInfo.CHANNEL_WIDTH_INVALID); + + order.verify(mCallback).onInfoChanged(mTestSoftApInfo); + order.verify(mWifiMetrics, never()).addSoftApChannelSwitchedEvent(0, + SoftApInfo.CHANNEL_WIDTH_INVALID, apConfig.getTargetMode()); + } + @Test public void updatesConnectedClients() throws Exception { SoftApModeConfiguration apConfig = diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 318acc102..a436d97c2 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -99,6 +99,7 @@ import android.net.wifi.ITrafficStateCallback; import android.net.wifi.ITxPacketCountListener; import android.net.wifi.ScanResult; import android.net.wifi.SoftApConfiguration; +import android.net.wifi.SoftApInfo; import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.KeyMgmt; @@ -198,7 +199,10 @@ public class WifiServiceImplTest extends WifiBaseTest { 4, 1100001, "\"yellow\"", true, true, "example.org", "Yellow"), WifiConfigurationTestUtil.generateWifiConfig( 5, 1100002, "\"magenta\"", false, false, null, null)); + private static final int TEST_AP_FREQUENCY = 2412; + private static final int TEST_AP_BANDWIDTH = SoftApInfo.CHANNEL_WIDTH_20MHZ; + private SoftApInfo mTestSoftApInfo; private AsyncChannel mAsyncChannel; private WifiServiceImpl mWifiServiceImpl; private TestLooper mLooper; @@ -383,6 +387,9 @@ public class WifiServiceImplTest extends WifiBaseTest { // permission not granted by default doThrow(SecurityException.class).when(mContext).enforceCallingOrSelfPermission( eq(Manifest.permission.NETWORK_SETUP_WIZARD), any()); + mTestSoftApInfo = new SoftApInfo(); + mTestSoftApInfo.setFrequency(TEST_AP_FREQUENCY); + mTestSoftApInfo.setBandwidth(TEST_AP_BANDWIDTH); } /** @@ -1927,6 +1934,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.dispatchAll(); verify(mClientSoftApCallback, never()).onStateChanged(WIFI_AP_STATE_DISABLED, 0); verify(mClientSoftApCallback, never()).onConnectedClientsChanged(any()); + verify(mClientSoftApCallback, never()).onInfoChanged(any()); } @@ -1949,6 +1957,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.dispatchAll(); verify(callback).onStateChanged(WIFI_AP_STATE_DISABLED, 0); verify(callback).onConnectedClientsChanged(Mockito.<WifiClient>anyList()); + verify(callback).onInfoChanged(new SoftApInfo()); } /** @@ -2029,6 +2038,7 @@ public class WifiServiceImplTest extends WifiBaseTest { final List<WifiClient> testClients = new ArrayList(); mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0); mStateMachineSoftApCallback.onConnectedClientsChanged(testClients); + mStateMachineSoftApCallback.onInfoChanged(mTestSoftApInfo); // Register another callback and verify the new state is returned in the immediate callback final int anotherUid = 2; @@ -2036,6 +2046,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.dispatchAll(); verify(mAnotherSoftApCallback).onStateChanged(WIFI_AP_STATE_ENABLED, 0); verify(mAnotherSoftApCallback).onConnectedClientsChanged(testClients); + verify(mAnotherSoftApCallback).onInfoChanged(mTestSoftApInfo); // unregister the fisrt callback mWifiServiceImpl.unregisterSoftApCallback(callbackIdentifier); @@ -2123,6 +2134,7 @@ public class WifiServiceImplTest extends WifiBaseTest { final List<WifiClient> testClients = new ArrayList(); mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0); mStateMachineSoftApCallback.onConnectedClientsChanged(testClients); + mStateMachineSoftApCallback.onInfoChanged(mTestSoftApInfo); // Register callback after num clients and soft AP are changed. final int callbackIdentifier = 1; @@ -2131,6 +2143,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.dispatchAll(); verify(mClientSoftApCallback).onStateChanged(WIFI_AP_STATE_ENABLED, 0); verify(mClientSoftApCallback).onConnectedClientsChanged(testClients); + verify(mClientSoftApCallback).onInfoChanged(mTestSoftApInfo); } private class IntentFilterMatcher implements ArgumentMatcher<IntentFilter> { |