Merge "Address leftover comments on 923337 and 930217."

This commit is contained in:
Paul Hu
2019-04-02 07:39:04 +00:00
committed by Gerrit Code Review
5 changed files with 83 additions and 20 deletions

View File

@@ -3046,6 +3046,47 @@ public class ConnectivityServiceTest {
}
}
@Test
public void testInvalidSignalStrength() {
NetworkRequest r = new NetworkRequest.Builder()
.addCapability(NET_CAPABILITY_INTERNET)
.addTransportType(TRANSPORT_WIFI)
.setSignalStrength(-75)
.build();
// Registering a NetworkCallback with signal strength but w/o NETWORK_SIGNAL_STRENGTH_WAKEUP
// permission should get SecurityException.
try {
mCm.registerNetworkCallback(r, new NetworkCallback());
fail("Expected SecurityException filing a callback with signal strength");
} catch (SecurityException expected) {
// expected
}
try {
mCm.registerNetworkCallback(r, PendingIntent.getService(
mServiceContext, 0, new Intent(), 0));
fail("Expected SecurityException filing a callback with signal strength");
} catch (SecurityException expected) {
// expected
}
// Requesting a Network with signal strength should get IllegalArgumentException.
try {
mCm.requestNetwork(r, new NetworkCallback());
fail("Expected IllegalArgumentException filing a request with signal strength");
} catch (IllegalArgumentException expected) {
// expected
}
try {
mCm.requestNetwork(r, PendingIntent.getService(
mServiceContext, 0, new Intent(), 0));
fail("Expected IllegalArgumentException filing a request with signal strength");
} catch (IllegalArgumentException expected) {
// expected
}
}
@Test
public void testRegisterDefaultNetworkCallback() throws Exception {
final TestNetworkCallback defaultNetworkCallback = new TestNetworkCallback();