summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java54
2 files changed, 57 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 9836e03f8..7840b09ec 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -1258,12 +1258,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
* requesting app holds the WIFI_CONFIG_OVERRIDE permission.
*/
private boolean connectToUserSelectNetwork(int netId, int uid) {
- if (!mWifiConfigManager.enableNetwork(netId, true, uid)) {
- loge("connectToUserSelectNetwork uid " + uid
- + " did not have the permissions to enable=" + netId);
+ if (mWifiConfigManager.getConfiguredNetwork(netId) == null) {
+ loge("connectToUserSelectNetwork Invalid network Id=" + netId);
return false;
}
- if (!mWifiConfigManager.checkAndUpdateLastConnectUid(netId, uid)) {
+ if (!mWifiConfigManager.enableNetwork(netId, true, uid)
+ || !mWifiConfigManager.checkAndUpdateLastConnectUid(netId, uid)) {
logi("connectToUserSelectNetwork Allowing uid " + uid
+ " with insufficient permissions to connect=" + netId);
}
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.