diff options
author | Sunil Ravi <sunilravi@google.com> | 2019-10-31 19:23:32 -0700 |
---|---|---|
committer | Sunil Ravi <sunilravi@google.com> | 2019-11-08 12:13:04 -0800 |
commit | 7a541e4f82801e22f62b4e6b91a641d32935df30 (patch) | |
tree | baca44aa872762ad7c4f0728002e3debc68796dc /tests | |
parent | c80e77863c27765f1ca5879f00164f433acc6680 (diff) |
wifi: MBO-OCE feature support (phase 1)
1. Added the functionality to get MBO and OCE feature capability from
wpa_supplicant.
2. Added the functionality to update the cellular data status.
Bug: 139474288
Test: atest com.android.server.wifi
Test: Manual
Change-Id: Ie93db3b2129b48a65b3a30b148a8a2bdc01e410a
Diffstat (limited to 'tests')
4 files changed, 233 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index bec150f99..14a1a370e 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -387,6 +387,7 @@ public class ClientModeImplTest extends WifiBaseTest { @Mock CarrierNetworkConfig mCarrierNetworkConfig; @Mock Handler mNetworkAgentHandler; @Mock BatteryStatsManager mBatteryStatsManager; + @Mock MboOceController mMboOceController; final ArgumentCaptor<WifiConfigManager.OnNetworkUpdateListener> mConfigUpdateListenerCaptor = ArgumentCaptor.forClass(WifiConfigManager.OnNetworkUpdateListener.class); @@ -543,7 +544,8 @@ public class ClientModeImplTest extends WifiBaseTest { mCmi = new ClientModeImpl(mContext, mFrameworkFacade, mLooper.getLooper(), mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative, mWrongPasswordNotifier, mSarManager, mWifiTrafficPoller, - mLinkProbeManager, mBatteryStatsManager, mSupplicantStateTracker); + mLinkProbeManager, mBatteryStatsManager, mSupplicantStateTracker, + mMboOceController); mCmi.start(); mWifiCoreThread = getCmiHandlerThread(mCmi); @@ -3780,4 +3782,16 @@ public class ClientModeImplTest extends WifiBaseTest { assertEquals("ConnectedState", getCurrentState().getName()); } + + /** + * Verify that MboOce initialization/Deinitialization methods are called in ClientMode. + */ + @Test + public void verifyMboOceInitAndDeinitInClientMode() throws Exception { + startSupplicantAndDispatchMessages(); + verify(mMboOceController).enable(); + mCmi.setOperationalMode(ClientModeImpl.DISABLED_MODE, null); + mLooper.dispatchAll(); + verify(mMboOceController).disable(); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/MboOceControllerTest.java b/tests/wifitests/src/com/android/server/wifi/MboOceControllerTest.java new file mode 100644 index 000000000..239fea95f --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/MboOceControllerTest.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.*; + +import android.net.wifi.WifiManager; +import android.os.test.TestLooper; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; + +import androidx.test.filters.SmallTest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + + +/** + * unit tests for {@link com.android.server.wifi.MboOceController}. + */ +@SmallTest +public class MboOceControllerTest extends WifiBaseTest { + private static final String TAG = "MboOceControllerTest"; + private static final String INTERFACE_NAME = "wlan0"; + + private MboOceController mMboOceController; + private TestLooper mLooper; + @Mock WifiNative mWifiNative; + @Mock TelephonyManager mTelephonyManager; + + /** + * Initializes common state (e.g. mocks) needed by test cases. + */ + @Before + public void setUp() throws Exception { + /* Ensure Looper exists */ + mLooper = new TestLooper(); + MockitoAnnotations.initMocks(this); + + mMboOceController = new MboOceController(mTelephonyManager, mWifiNative); + + when(mWifiNative.getClientInterfaceName()).thenReturn(INTERFACE_NAME); + } + + /** + * Helper function to initialize mboOceController + */ + private PhoneStateListener enableMboOceController(boolean isMboEnabled, boolean isOceEnabled) { + long featureSet = 0; + PhoneStateListener dataConnectionStateListener = null; + + if (isMboEnabled) { + featureSet |= WifiManager.WIFI_FEATURE_MBO; + } + if (isOceEnabled) { + featureSet |= WifiManager.WIFI_FEATURE_OCE; + } + when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME)) + .thenReturn((long) featureSet); + + mMboOceController.enable(); + + if (isMboEnabled) { + /* Capture the PhoneStateListener */ + ArgumentCaptor<PhoneStateListener> phoneStateListenerCaptor = + ArgumentCaptor.forClass(PhoneStateListener.class); + verify(mTelephonyManager).listen(phoneStateListenerCaptor.capture(), + eq(PhoneStateListener.LISTEN_DATA_CONNECTION_STATE)); + dataConnectionStateListener = phoneStateListenerCaptor.getValue(); + assertNotNull(dataConnectionStateListener); + } + + return dataConnectionStateListener; + + } + + /** + * Test that we do not register for cellular Data state change + * events when MBO is disabled. + */ + @Test + public void testMboDisabledDoNotRegisterCellularDataStateChangeEvents() + throws Exception { + enableMboOceController(false, false); + verify(mTelephonyManager, never()).listen(any(), anyInt()); + } + + /** + * Test that we register for cellular Data state change + * events and update cellular data status changes when MBO is enabled. + */ + @Test + public void testMboEnabledUpdateCellularDataStateChangeEvents() throws Exception { + InOrder inOrder = inOrder(mWifiNative); + PhoneStateListener dataConnectionStateListener; + dataConnectionStateListener = enableMboOceController(true, false); + dataConnectionStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, + TelephonyManager.NETWORK_TYPE_LTE); + verify(mWifiNative).setMboCellularDataStatus(eq(INTERFACE_NAME), eq(true)); + dataConnectionStateListener.onDataConnectionStateChanged( + TelephonyManager.DATA_DISCONNECTED, TelephonyManager.NETWORK_TYPE_LTE); + verify(mWifiNative).setMboCellularDataStatus(eq(INTERFACE_NAME), eq(false)); + } + + /** + * Test that we unregister data connection state events + * when disable mMboOceController is called. + */ + @Test + public void testDisableMboOceControllerUnRegisterCellularDataStateChangeEvents() + throws Exception { + enableMboOceController(true, false); + mMboOceController.disable(); + ArgumentCaptor<PhoneStateListener> phoneStateListenerCaptor = + ArgumentCaptor.forClass(PhoneStateListener.class); + verify(mTelephonyManager).listen(phoneStateListenerCaptor.capture(), + eq(PhoneStateListener.LISTEN_NONE)); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index fc8ae0cf0..b071786d3 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -16,6 +16,8 @@ package com.android.server.wifi; import static android.net.wifi.WifiManager.WIFI_FEATURE_DPP; +import static android.net.wifi.WifiManager.WIFI_FEATURE_MBO; +import static android.net.wifi.WifiManager.WIFI_FEATURE_OCE; import static android.net.wifi.WifiManager.WIFI_FEATURE_OWE; import static android.net.wifi.WifiManager.WIFI_FEATURE_WPA3_SAE; import static android.net.wifi.WifiManager.WIFI_FEATURE_WPA3_SUITE_B; @@ -2361,4 +2363,70 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { }).when(mSupplicantStaNetworkMock) .setPmkCache(any(ArrayList.class)); } + + private class GetWpaDriverCapabilitiesAnswer extends MockAnswerUtil.AnswerWithArguments { + private int mWpaDriverCapabilities; + + GetWpaDriverCapabilitiesAnswer(int wpaDriverCapabilities) { + mWpaDriverCapabilities = wpaDriverCapabilities; + } + + public void answer(android.hardware.wifi.supplicant.V1_3.ISupplicantStaIface + .getWpaDriverCapabilitiesCallback cb) { + cb.onValues(mStatusSuccess, mWpaDriverCapabilities); + } + } + + /** + * Test To get wpa driver capabilities API on old HAL, should + * return 0 (not supported) + */ + @Test + public void tetGetWpaDriverCapabilitiesOldHal() throws Exception { + setupMocksForHalV1_2(); + + executeAndValidateInitializationSequenceV1_2(); + + assertEquals(0, mDut.getWpaDriverFeatureSet(WLAN0_IFACE_NAME)); + } + + /** + * Test Multi Band operation support (MBO). + */ + @Test + public void testGetWpaDriverCapabilitiesMbo() throws Exception { + setupMocksForHalV1_3(); + + executeAndValidateInitializationSequenceV1_3(); + + doAnswer(new GetWpaDriverCapabilitiesAnswer(android.hardware.wifi.supplicant.V1_3 + .WpaDriverCapabilitiesMask.MBO)) + .when(mISupplicantStaIfaceMockV13).getWpaDriverCapabilities(any( + android.hardware.wifi.supplicant.V1_3.ISupplicantStaIface + .getWpaDriverCapabilitiesCallback.class)); + + assertEquals(WIFI_FEATURE_MBO, mDut.getWpaDriverFeatureSet(WLAN0_IFACE_NAME)); + } + + /** + * Test Optimized Connectivity support (OCE). + */ + @Test + public void testGetWpaDriverCapabilitiesOce() throws Exception { + setupMocksForHalV1_3(); + + executeAndValidateInitializationSequenceV1_3(); + + doAnswer(new GetWpaDriverCapabilitiesAnswer(android.hardware.wifi.supplicant.V1_3 + .WpaDriverCapabilitiesMask.MBO + | android.hardware.wifi.supplicant.V1_3 + .WpaDriverCapabilitiesMask.OCE)) + .when(mISupplicantStaIfaceMockV13).getWpaDriverCapabilities(any( + android.hardware.wifi.supplicant.V1_3.ISupplicantStaIface + .getWpaDriverCapabilitiesCallback.class)); + + assertEquals(WIFI_FEATURE_MBO | WIFI_FEATURE_OCE, + mDut.getWpaDriverFeatureSet(WLAN0_IFACE_NAME)); + } + } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java index ccd81856b..68c59081a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java @@ -452,6 +452,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).getInterfaceConfig(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); // Execute a teardown of the interface to ensure that the new iface removal works. executeAndValidateTeardownSoftApInterface(false, false, IFACE_NAME_0, mIfaceCallback1, @@ -504,6 +505,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).disableIpv6(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); // Execute a teardown of the interface to ensure that the new iface removal works. executeAndValidateTeardownClientInterface(false, false, IFACE_NAME_0, mIfaceCallback1, @@ -715,6 +717,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).getInterfaceConfig(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); // Step (c) - Iface up on old iface, ignored! mNetworkObserverCaptor0.getValue().interfaceLinkStateChanged(IFACE_NAME_0, true); @@ -1174,6 +1177,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).disableIpv6(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); // Now setup an AP interface. assertEquals(IFACE_NAME_0, mWifiNative.setupInterfaceForSoftApMode(mIfaceCallback1)); @@ -1199,6 +1203,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).getInterfaceConfig(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); } /** @@ -1227,6 +1232,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).getInterfaceConfig(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); // Now setup a STA interface. assertEquals(IFACE_NAME_0, @@ -1257,6 +1263,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).disableIpv6(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); } /** @@ -1295,6 +1302,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mSupplicantStaIfaceHal).terminate(); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); } /** @@ -1326,6 +1334,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mSupplicantStaIfaceHal).setupIface(IFACE_NAME_0); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(IFACE_NAME_0); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(IFACE_NAME_0); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(IFACE_NAME_0); } /** @@ -1400,6 +1409,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).disableIpv6(ifaceName); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(ifaceName); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(ifaceName); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(ifaceName); } private void executeAndValidateTeardownClientInterface( @@ -1472,6 +1482,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).getInterfaceConfig(ifaceName); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(ifaceName); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(ifaceName); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(ifaceName); } private void executeAndValidateTeardownClientInterfaceForScan( @@ -1544,6 +1555,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { mInOrder.verify(mNwManagementService).getInterfaceConfig(ifaceName); mInOrder.verify(mSupplicantStaIfaceHal).getAdvancedKeyMgmtCapabilities(ifaceName); mInOrder.verify(mWifiVendorHal).getSupportedFeatureSet(ifaceName); + mInOrder.verify(mSupplicantStaIfaceHal).getWpaDriverFeatureSet(ifaceName); } private void executeAndValidateTeardownSoftApInterface( |