diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkFactory.java | 28 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java | 33 |
2 files changed, 54 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java index 65d78e6aa..ecc1a9f18 100644 --- a/service/java/com/android/server/wifi/WifiNetworkFactory.java +++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java @@ -478,6 +478,23 @@ public class WifiNetworkFactory extends NetworkFactory { return false; } + boolean isRequestWithNetworkSpecifierValid(NetworkRequest networkRequest) { + NetworkSpecifier ns = networkRequest.networkCapabilities.getNetworkSpecifier(); + // Invalid network specifier. + if (!(ns instanceof WifiNetworkSpecifier)) { + Log.e(TAG, "Invalid network specifier mentioned. Rejecting"); + return false; + } + // Request cannot have internet capability since such a request can never be fulfilled. + // (NetworkAgent for connection with WifiNetworkSpecifier will not have internet capability) + if (networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { + Log.e(TAG, "Request with wifi network specifier cannot contain " + + "NET_CAPABILITY_INTERNET. Rejecting"); + return false; + } + return true; + } + /** * Check whether to accept the new network connection request. * @@ -486,13 +503,11 @@ public class WifiNetworkFactory extends NetworkFactory { @Override public boolean acceptRequest(NetworkRequest networkRequest, int score) { NetworkSpecifier ns = networkRequest.networkCapabilities.getNetworkSpecifier(); - // Generic wifi request. Always accept. if (ns == null) { // Generic wifi request. Always accept. } else { - // Invalid network specifier. - if (!(ns instanceof WifiNetworkSpecifier)) { - Log.e(TAG, "Invalid network specifier mentioned. Rejecting"); + // Invalid request with network specifier. + if (!isRequestWithNetworkSpecifierValid(networkRequest)) { releaseRequestAsUnfulfillableByAnyFactory(networkRequest); return false; } @@ -569,9 +584,8 @@ public class WifiNetworkFactory extends NetworkFactory { mWifiConnectivityManager.setTrustedConnectionAllowed(true); } } else { - // Invalid network specifier. - if (!(ns instanceof WifiNetworkSpecifier)) { - Log.e(TAG, "Invalid network specifier mentioned. Rejecting"); + // Invalid request with network specifier. + if (!isRequestWithNetworkSpecifierValid(networkRequest)) { releaseRequestAsUnfulfillableByAnyFactory(networkRequest); return; } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index 118b96245..d4e6594c8 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -279,6 +279,24 @@ public class WifiNetworkFactoryTest { } /** + * Validates handling of acceptNetwork with a network specifier with internet capability. + */ + @Test + public void testHandleAcceptNetworkRequestFromWithInternetCapability() throws Exception { + when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1)) + .thenReturn(IMPORTANCE_FOREGROUND); + + WifiNetworkSpecifier specifier = createWifiNetworkSpecifier(TEST_UID_1, false); + mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier); + mNetworkRequest.networkCapabilities.addCapability( + NetworkCapabilities.NET_CAPABILITY_INTERNET); + + assertFalse(mWifiNetworkFactory.acceptRequest(mNetworkRequest, 0)); + mLooper.dispatchAll(); + verifyUnfullfillableDispatched(mConnectivityMessenger); + } + + /** * Validates handling of acceptNetwork with a network specifier from a non foreground * app/service. */ @@ -499,6 +517,21 @@ public class WifiNetworkFactoryTest { } /** + * Validates handling of new network request with network specifier with internet capability. + */ + @Test + public void testHandleNetworkRequestWithSpecifierAndInternetCapability() throws Exception { + WifiNetworkSpecifier specifier = createWifiNetworkSpecifier(TEST_UID_1, false); + mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier); + mNetworkRequest.networkCapabilities.addCapability( + NetworkCapabilities.NET_CAPABILITY_INTERNET); + + mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0); + mLooper.dispatchAll(); + verifyUnfullfillableDispatched(mConnectivityMessenger); + } + + /** * Verify handling of new network request with network specifier for a hidden network. */ @Test |