From f2893a20c5ce5094b3838778de157943254b3586 Mon Sep 17 00:00:00 2001 From: David Su Date: Fri, 5 Jun 2020 17:30:17 -0700 Subject: WifiManager#getCurrentNetwork: return null if not L3 connected According to the API contract of Network, Wifi should not expose a Network object before it is L3 connected. Previously, getCurrentNetwork returned a non-null Network object after L2ConnectedState. Changed to only return a Network object in ConnectedState/RoamingState. Return null in all other states. Note that getCurrentNetwork was marked as @Nullable and did return null when Wifi was disconnected, so callers should be able to handle this change in behavior. Bug: 150188453 Test: connect to network using SUW Test: connect/disconnect to network using Settings Test: atest ClientModeImplTest Change-Id: Ib65664b7925176bc34287d37bcd1ba1085c351a4 Merged-In: Ib65664b7925176bc34287d37bcd1ba1085c351a4 (dirty cherry-pick from master) --- .../android/server/wifi/ClientModeImplTest.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 20766898d..58f5b1ccc 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -421,6 +421,7 @@ public class ClientModeImplTest extends WifiBaseTest { @Mock ThroughputPredictor mThroughputPredictor; @Mock ScanRequestProxy mScanRequestProxy; @Mock DeviceConfigFacade mDeviceConfigFacade; + @Mock Network mNetwork; final ArgumentCaptor mConfigUpdateListenerCaptor = ArgumentCaptor.forClass(WifiConfigManager.OnNetworkUpdateListener.class); @@ -533,10 +534,8 @@ public class ClientModeImplTest extends WifiBaseTest { return null; }).when(mIpClient).shutdown(); when(mConnectivityManager.registerNetworkAgent(any(), any(), any(), any(), anyInt(), any(), - anyInt())).thenReturn(mock(Network.class)); - List subList = new ArrayList<>() {{ - add(mock(SubscriptionInfo.class)); - }}; + anyInt())).thenReturn(mNetwork); + List subList = Arrays.asList(mock(SubscriptionInfo.class)); when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(subList); when(mSubscriptionManager.getActiveSubscriptionIdList()) .thenReturn(new int[]{DATA_SUBID}); @@ -5266,4 +5265,19 @@ public class ClientModeImplTest extends WifiBaseTest { verifyNoMoreInteractions(mNetworkAgentHandler); } + + @Test + public void testSyncGetCurrentNetwork() throws Exception { + // syncGetCurrentNetwork() returns null when disconnected + mLooper.startAutoDispatch(); + assertNull(mCmi.syncGetCurrentNetwork(mCmiAsyncChannel)); + mLooper.stopAutoDispatch(); + + connect(); + + // syncGetCurrentNetwork() returns non-null Network when connected + mLooper.startAutoDispatch(); + assertEquals(mNetwork, mCmi.syncGetCurrentNetwork(mCmiAsyncChannel)); + mLooper.stopAutoDispatch(); + } } -- cgit v1.2.3