diff options
author | Roshan Pius <rpius@google.com> | 2017-03-08 15:10:20 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2017-03-10 18:49:46 +0000 |
commit | 4a5f4e08d677a6da1b436e58d027de99518a97cf (patch) | |
tree | c456804860aaf54b34ad8a1653cbc4bf9b8a73f8 /tests | |
parent | b8b3fb8228a1f90106bad8c59ce006b81ef7921c (diff) |
WifiStateMachine: Allow any app to initiate connection
This brings the existing API's in parity with behaviour in N. We allow
apps to initiate connection to a network even if they have no permission
to modify it.
Bug: 36040264
Test: Unit tests
Change-Id: I3316877ea88969fe4397552fea9461acb4d52cf2
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 59f26bce7..f77db43a4 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -816,7 +816,43 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); mLooper.startAutoDispatch(); - mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true); + assertTrue(mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true)); + mLooper.stopAutoDispatch(); + + verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt()); + + mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID); + mLooper.dispatchAll(); + + mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0, + new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED)); + mLooper.dispatchAll(); + + assertEquals("ObtainingIpState", getCurrentState().getName()); + + DhcpResults dhcpResults = new DhcpResults(); + dhcpResults.setGateway("1.2.3.4"); + dhcpResults.setIpAddress("192.168.1.100", 0); + dhcpResults.addDns("8.8.8.8"); + dhcpResults.setLeaseDuration(3600); + + mTestIpManager.injectDhcpSuccess(dhcpResults); + mLooper.dispatchAll(); + + assertEquals("ConnectedState", getCurrentState().getName()); + } + + @Test + public void connectWithNoEnablePermission() throws Exception { + addNetworkAndVerifySuccess(); + when(mWifiConfigManager.enableNetwork(eq(0), eq(true), anyInt())).thenReturn(false); + when(mWifiConfigManager.checkAndUpdateLastConnectUid(eq(0), anyInt())).thenReturn(false); + + mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE); + mLooper.dispatchAll(); + + mLooper.startAutoDispatch(); + assertTrue(mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true)); mLooper.stopAutoDispatch(); verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt()); @@ -842,6 +878,22 @@ public class WifiStateMachineTest { assertEquals("ConnectedState", getCurrentState().getName()); } + @Test + public void enableWithInvalidNetworkId() throws Exception { + addNetworkAndVerifySuccess(); + when(mWifiConfigManager.getConfiguredNetwork(eq(0))).thenReturn(null); + + mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE); + mLooper.dispatchAll(); + + mLooper.startAutoDispatch(); + assertFalse(mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true)); + mLooper.stopAutoDispatch(); + + verify(mWifiConfigManager, never()).enableNetwork(eq(0), eq(true), anyInt()); + verify(mWifiConfigManager, never()).checkAndUpdateLastConnectUid(eq(0), anyInt()); + } + /** * If caller tries to connect to a network that is already connected, the connection request * should succeed. |