Address leftover comments on 923337 and 930217.

- Restrict unprivileged apps to use
  NetworkRequest.Builder#setSignalStrength.

- Remove the "throws NullPointerException" in
  CaptivePortalProbeSpec constructor.

- Remove the null check in LinkProperties.

- Add annotataion into all ConnectivityManager.NetworkCallback
  methods.

Change-Id: Id275cac1d6a30d7515cd7b113394f5e8a0179314
Fix: 129097486
Test: atest FrameworksNetTests
This commit is contained in:
paulhu
2019-03-22 16:35:06 +08:00
parent 539821c978
commit 1a40765101
5 changed files with 83 additions and 20 deletions

View File

@@ -3022,6 +3022,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();