summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-05-14 12:50:45 -0700
committerRoshan Pius <rpius@google.com>2018-05-15 12:16:02 -0700
commit8964a106164d84089c1ee52b62973c346115822b (patch)
tree75497a6dd86897e52ce051f04d07b24ee0a5f196
parentd0b1c6de370037885cf0da1eb202efff23c746b4 (diff)
Only allow settings app to set user choice
3rd party app connect requests should not set user choice. User choice was meant to capture explicit network selections by the user from settings app. Bug: 72635747 Test: Unit tests Change-Id: I8d15e262447c5d120c91f0f7213e57a13a088769
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java33
2 files changed, 31 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 5e49a4c6f..1d40360f9 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -1142,7 +1142,7 @@ public class WifiStateMachine extends StateMachine {
|| !mWifiConfigManager.updateLastConnectUid(netId, uid)) {
logi("connectToUserSelectNetwork Allowing uid " + uid
+ " with insufficient permissions to connect=" + netId);
- } else {
+ } else if (mWifiPermissionsUtil.checkNetworkSettingsPermission(uid)) {
// Note user connect choice here, so that it will be considered in the next network
// selection.
mWifiConnectivityManager.setUserConnectChoice(netId);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 7c0739b83..2712a42e3 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -903,6 +903,28 @@ public class WifiStateMachineTest {
}
/**
+ * Tests the network connection initiation sequence with the default network request pending
+ * from WifiNetworkFactory.
+ * This simulates the connect sequence using the public
+ * {@link WifiManager#enableNetwork(int, boolean)} and ensures that we invoke
+ * {@link WifiNative#connectToNetwork(WifiConfiguration)}.
+ */
+ @Test
+ public void triggerConnectFromNonSettingsApp() throws Exception {
+ loadComponentsInStaMode();
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ config.networkId = FRAMEWORK_NETWORK_ID;
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(Process.myUid()))
+ .thenReturn(false);
+ setupAndStartConnectSequence(config);
+ verify(mWifiConfigManager).enableNetwork(eq(config.networkId), eq(true), anyInt());
+ verify(mWifiConnectivityManager, never()).setUserConnectChoice(eq(config.networkId));
+ verify(mWifiConnectivityManager).prepareForForcedConnection(eq(config.networkId));
+ verify(mWifiConfigManager).getConfiguredNetworkWithoutMasking(eq(config.networkId));
+ verify(mWifiNative).connectToNetwork(eq(WIFI_IFACE_NAME), eq(config));
+ }
+
+ /**
* Tests the network connection initiation sequence with no network request pending from
* from WifiNetworkFactory.
* This simulates the connect sequence using the public
@@ -995,7 +1017,7 @@ public class WifiStateMachineTest {
config.networkId = FRAMEWORK_NETWORK_ID + 1;
setupAndStartConnectSequence(config);
validateSuccessfulConnectSequence(config);
- verify(mWifiPermissionsUtil, times(2)).checkNetworkSettingsPermission(anyInt());
+ verify(mWifiPermissionsUtil, times(4)).checkNetworkSettingsPermission(anyInt());
}
/**
@@ -1020,8 +1042,13 @@ public class WifiStateMachineTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
config.networkId = FRAMEWORK_NETWORK_ID + 1;
setupAndStartConnectSequence(config);
- validateFailureConnectSequence(config);
- verify(mWifiPermissionsUtil, times(2)).checkNetworkSettingsPermission(anyInt());
+ verify(mWifiConfigManager).enableNetwork(eq(config.networkId), eq(true), anyInt());
+ verify(mWifiConnectivityManager, never()).setUserConnectChoice(eq(config.networkId));
+ verify(mWifiConnectivityManager).prepareForForcedConnection(eq(config.networkId));
+ verify(mWifiConfigManager, never())
+ .getConfiguredNetworkWithoutMasking(eq(config.networkId));
+ verify(mWifiNative, never()).connectToNetwork(eq(WIFI_IFACE_NAME), eq(config));
+ verify(mWifiPermissionsUtil, times(4)).checkNetworkSettingsPermission(anyInt());
}
@Test