summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2020-06-05 17:30:17 -0700
committerDavid Su <dysu@google.com>2020-06-09 01:01:42 +0000
commitf2893a20c5ce5094b3838778de157943254b3586 (patch)
treebee85fcaad630ef8a58bbb21d8781c1672471093 /tests
parente565c0b697b0760443aceb02f9933e2a455da616 (diff)
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)
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java22
1 files changed, 18 insertions, 4 deletions
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<WifiConfigManager.OnNetworkUpdateListener> 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<SubscriptionInfo> subList = new ArrayList<>() {{
- add(mock(SubscriptionInfo.class));
- }};
+ anyInt())).thenReturn(mNetwork);
+ List<SubscriptionInfo> 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();
+ }
}