summaryrefslogtreecommitdiffstats
path: root/services/tests/servicestests/src
diff options
context:
space:
mode:
authorPaul Jensen <pauljensen@google.com>2015-06-16 15:11:58 -0400
committerPaul Jensen <pauljensen@google.com>2015-06-23 14:13:10 -0400
commitbb2e0e98160f099261876794518d4db62e309aec (patch)
tree856b5e237d754a0ddedfe85007e66c5559d8d606 /services/tests/servicestests/src
parent1c7ba0285b3fe8de479d6c09b2ff45572913c2cb (diff)
downloadframeworks_base-bb2e0e98160f099261876794518d4db62e309aec.zip
frameworks_base-bb2e0e98160f099261876794518d4db62e309aec.tar.gz
frameworks_base-bb2e0e98160f099261876794518d4db62e309aec.tar.bz2
Disallow requesting networks with mutable NetworkCapabilities.
It's not clear what it means to request a network with a mutable NetworkCapability like NET_CAPABILITY_VALIDATED or NET_CAPABILITY_CAPTIVE_PORTAL. Presently requesting such a network would fail in a number of different ways: 1. The NetworkFactories would fail to match the request against their filter which doesn't include stateful NetworkCapabilities. 2. If the NetworkFactories did match, they'd bring up networks to try and satisfy the requests, but the networks would not have any mutable NetworkCapabilities initially so they'd be reaped. Because of these problems it's safest to simply disallow these requests. Bug: 21343774 Change-Id: I56303242b81d39b370b8d5d1e32059bfcfc25949
Diffstat (limited to 'services/tests/servicestests/src')
-rw-r--r--services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java b/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java
index 712db09..fb8a5bb 100644
--- a/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java
@@ -34,6 +34,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
+import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.ContextWrapper;
@@ -792,6 +793,30 @@ public class ConnectivityServiceTest extends AndroidTestCase {
handlerThread.quit();
}
+ @LargeTest
+ public void testNoMutableNetworkRequests() throws Exception {
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a"), 0);
+ NetworkRequest.Builder builder = new NetworkRequest.Builder();
+ builder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
+ try {
+ mCm.requestNetwork(builder.build(), new NetworkCallback());
+ fail();
+ } catch (IllegalArgumentException expected) {}
+ try {
+ mCm.requestNetwork(builder.build(), pendingIntent);
+ fail();
+ } catch (IllegalArgumentException expected) {}
+ builder = new NetworkRequest.Builder();
+ builder.addCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
+ try {
+ mCm.requestNetwork(builder.build(), new NetworkCallback());
+ fail();
+ } catch (IllegalArgumentException expected) {}
+ try {
+ mCm.requestNetwork(builder.build(), pendingIntent);
+ fail();
+ } catch (IllegalArgumentException expected) {}
+ }
// @Override
// public void tearDown() throws Exception {