Merge "Add a mode for cell radios unable to time share"

This commit is contained in:
Chalard Jean
2021-09-18 12:39:24 +00:00
committed by Gerrit Code Review
6 changed files with 280 additions and 12 deletions

View File

@@ -1792,6 +1792,8 @@ public class ConnectivityServiceTest {
doReturn(R.integer.config_networkAvoidBadWifi).when(mResources)
.getIdentifier(eq("config_networkAvoidBadWifi"), eq("integer"), any());
doReturn(1).when(mResources).getInteger(R.integer.config_networkAvoidBadWifi);
doReturn(true).when(mResources)
.getBoolean(R.bool.config_cellular_radio_timesharing_capable);
final ConnectivityResources connRes = mock(ConnectivityResources.class);
doReturn(mResources).when(connRes).get();
@@ -2273,8 +2275,22 @@ public class ConnectivityServiceTest {
// After waitForIdle(), the message was processed and the service didn't crash.
}
// TODO : migrate to @Parameterized
@Test
public void testValidatedCellularOutscoresUnvalidatedWiFi() throws Exception {
public void testValidatedCellularOutscoresUnvalidatedWiFi_CanTimeShare() throws Exception {
// The behavior of this test should be the same whether the radio can time share or not.
doTestValidatedCellularOutscoresUnvalidatedWiFi(true);
}
// TODO : migrate to @Parameterized
@Test
public void testValidatedCellularOutscoresUnvalidatedWiFi_CannotTimeShare() throws Exception {
doTestValidatedCellularOutscoresUnvalidatedWiFi(false);
}
public void doTestValidatedCellularOutscoresUnvalidatedWiFi(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up unvalidated WiFi
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
ExpectedBroadcast b = registerConnectivityBroadcast(1);
@@ -2308,8 +2324,21 @@ public class ConnectivityServiceTest {
verifyNoNetwork();
}
// TODO : migrate to @Parameterized
@Test
public void testUnvalidatedWifiOutscoresUnvalidatedCellular() throws Exception {
public void testUnvalidatedWifiOutscoresUnvalidatedCellular_CanTimeShare() throws Exception {
doTestUnvalidatedWifiOutscoresUnvalidatedCellular(true);
}
// TODO : migrate to @Parameterized
@Test
public void testUnvalidatedWifiOutscoresUnvalidatedCellular_CannotTimeShare() throws Exception {
doTestUnvalidatedWifiOutscoresUnvalidatedCellular(false);
}
public void doTestUnvalidatedWifiOutscoresUnvalidatedCellular(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up unvalidated cellular.
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
ExpectedBroadcast b = registerConnectivityBroadcast(1);
@@ -2334,8 +2363,21 @@ public class ConnectivityServiceTest {
verifyNoNetwork();
}
// TODO : migrate to @Parameterized
@Test
public void testUnlingeringDoesNotValidate() throws Exception {
public void testUnlingeringDoesNotValidate_CanTimeShare() throws Exception {
doTestUnlingeringDoesNotValidate(true);
}
// TODO : migrate to @Parameterized
@Test
public void testUnlingeringDoesNotValidate_CannotTimeShare() throws Exception {
doTestUnlingeringDoesNotValidate(false);
}
public void doTestUnlingeringDoesNotValidate(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up unvalidated WiFi.
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
ExpectedBroadcast b = registerConnectivityBroadcast(1);
@@ -2362,8 +2404,134 @@ public class ConnectivityServiceTest {
NET_CAPABILITY_VALIDATED));
}
// TODO : migrate to @Parameterized
@Test
public void testCellularOutscoresWeakWifi() throws Exception {
public void testRequestMigrationToSameTransport_CanTimeShare() throws Exception {
// Simulate a device where the cell radio is capable of time sharing
mService.mCellularRadioTimesharingCapable = true;
doTestRequestMigrationToSameTransport(TRANSPORT_CELLULAR, true);
doTestRequestMigrationToSameTransport(TRANSPORT_WIFI, true);
doTestRequestMigrationToSameTransport(TRANSPORT_ETHERNET, true);
}
// TODO : migrate to @Parameterized
@Test
public void testRequestMigrationToSameTransport_CannotTimeShare() throws Exception {
// Simulate a device where the cell radio is not capable of time sharing
mService.mCellularRadioTimesharingCapable = false;
doTestRequestMigrationToSameTransport(TRANSPORT_CELLULAR, false);
doTestRequestMigrationToSameTransport(TRANSPORT_WIFI, true);
doTestRequestMigrationToSameTransport(TRANSPORT_ETHERNET, true);
}
public void doTestRequestMigrationToSameTransport(final int transport,
final boolean expectLingering) throws Exception {
// To speed up tests the linger delay is very short by default in tests but this
// test needs to make sure the delay is not incurred so a longer value is safer (it
// reduces the risk that a bug exists but goes undetected). The alarm manager in the test
// throws and crashes CS if this is set to anything more than the below constant though.
mService.mLingerDelayMs = UNREASONABLY_LONG_ALARM_WAIT_MS;
final TestNetworkCallback generalCb = new TestNetworkCallback();
final TestNetworkCallback defaultCb = new TestNetworkCallback();
mCm.registerNetworkCallback(
new NetworkRequest.Builder().addTransportType(transport | transport).build(),
generalCb);
mCm.registerDefaultNetworkCallback(defaultCb);
// Bring up net agent 1
final TestNetworkAgentWrapper net1 = new TestNetworkAgentWrapper(transport);
net1.connect(true);
// Make sure the default request is on net 1
generalCb.expectAvailableThenValidatedCallbacks(net1);
defaultCb.expectAvailableThenValidatedCallbacks(net1);
// Bring up net 2 with primary and mms
final TestNetworkAgentWrapper net2 = new TestNetworkAgentWrapper(transport);
net2.addCapability(NET_CAPABILITY_MMS);
net2.setScore(new NetworkScore.Builder().setTransportPrimary(true).build());
net2.connect(true);
// Make sure the default request goes to net 2
generalCb.expectAvailableCallbacksUnvalidated(net2);
if (expectLingering) {
generalCb.expectCallback(CallbackEntry.LOSING, net1);
}
generalCb.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, net2);
defaultCb.expectAvailableDoubleValidatedCallbacks(net2);
// Make sure cell 1 is unwanted immediately if the radio can't time share, but only
// after some delay if it can.
if (expectLingering) {
net1.assertNotDisconnected(TEST_CALLBACK_TIMEOUT_MS); // always incurs the timeout
generalCb.assertNoCallback();
// assertNotDisconnected waited for TEST_CALLBACK_TIMEOUT_MS, so waiting for the
// linger period gives TEST_CALLBACK_TIMEOUT_MS time for the event to process.
net1.expectDisconnected(UNREASONABLY_LONG_ALARM_WAIT_MS);
} else {
net1.expectDisconnected(TEST_CALLBACK_TIMEOUT_MS);
}
net1.disconnect();
generalCb.expectCallback(CallbackEntry.LOST, net1);
// Remove primary from net 2
net2.setScore(new NetworkScore.Builder().build());
// Request MMS
final TestNetworkCallback mmsCallback = new TestNetworkCallback();
mCm.requestNetwork(new NetworkRequest.Builder().addCapability(NET_CAPABILITY_MMS).build(),
mmsCallback);
mmsCallback.expectAvailableCallbacksValidated(net2);
// Bring up net 3 with primary but without MMS
final TestNetworkAgentWrapper net3 = new TestNetworkAgentWrapper(transport);
net3.setScore(new NetworkScore.Builder().setTransportPrimary(true).build());
net3.connect(true);
// Make sure default goes to net 3, but the MMS request doesn't
generalCb.expectAvailableThenValidatedCallbacks(net3);
defaultCb.expectAvailableDoubleValidatedCallbacks(net3);
mmsCallback.assertNoCallback();
net2.assertNotDisconnected(TEST_CALLBACK_TIMEOUT_MS); // Always incurs the timeout
// Revoke MMS request and make sure net 2 is torn down with the appropriate delay
mCm.unregisterNetworkCallback(mmsCallback);
if (expectLingering) {
// If the radio can time share, the linger delay hasn't elapsed yet, so apps will
// get LOSING. If the radio can't time share, this is a hard loss, since the last
// request keeping up this network has been removed and the network isn't lingering
// for any other request.
generalCb.expectCallback(CallbackEntry.LOSING, net2);
net2.assertNotDisconnected(TEST_CALLBACK_TIMEOUT_MS);
generalCb.assertNoCallback();
net2.expectDisconnected(UNREASONABLY_LONG_ALARM_WAIT_MS);
} else {
net2.expectDisconnected(TEST_CALLBACK_TIMEOUT_MS);
}
net2.disconnect();
generalCb.expectCallback(CallbackEntry.LOST, net2);
defaultCb.assertNoCallback();
net3.disconnect();
mCm.unregisterNetworkCallback(defaultCb);
mCm.unregisterNetworkCallback(generalCb);
}
// TODO : migrate to @Parameterized
@Test
public void testCellularOutscoresWeakWifi_CanTimeShare() throws Exception {
// The behavior of this test should be the same whether the radio can time share or not.
doTestCellularOutscoresWeakWifi(true);
}
// TODO : migrate to @Parameterized
@Test
public void testCellularOutscoresWeakWifi_CannotTimeShare() throws Exception {
doTestCellularOutscoresWeakWifi(false);
}
public void doTestCellularOutscoresWeakWifi(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up validated cellular.
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
ExpectedBroadcast b = registerConnectivityBroadcast(1);
@@ -2388,8 +2556,21 @@ public class ConnectivityServiceTest {
verifyActiveNetwork(TRANSPORT_WIFI);
}
// TODO : migrate to @Parameterized
@Test
public void testReapingNetwork() throws Exception {
public void testReapingNetwork_CanTimeShare() throws Exception {
doTestReapingNetwork(true);
}
// TODO : migrate to @Parameterized
@Test
public void testReapingNetwork_CannotTimeShare() throws Exception {
doTestReapingNetwork(false);
}
public void doTestReapingNetwork(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up WiFi without NET_CAPABILITY_INTERNET.
// Expect it to be torn down immediately because it satisfies no requests.
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
@@ -2417,8 +2598,21 @@ public class ConnectivityServiceTest {
mWiFiNetworkAgent.expectDisconnected();
}
// TODO : migrate to @Parameterized
@Test
public void testCellularFallback() throws Exception {
public void testCellularFallback_CanTimeShare() throws Exception {
doTestCellularFallback(true);
}
// TODO : migrate to @Parameterized
@Test
public void testCellularFallback_CannotTimeShare() throws Exception {
doTestCellularFallback(false);
}
public void doTestCellularFallback(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up validated cellular.
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
ExpectedBroadcast b = registerConnectivityBroadcast(1);
@@ -2455,8 +2649,21 @@ public class ConnectivityServiceTest {
verifyActiveNetwork(TRANSPORT_WIFI);
}
// TODO : migrate to @Parameterized
@Test
public void testWiFiFallback() throws Exception {
public void testWiFiFallback_CanTimeShare() throws Exception {
doTestWiFiFallback(true);
}
// TODO : migrate to @Parameterized
@Test
public void testWiFiFallback_CannotTimeShare() throws Exception {
doTestWiFiFallback(false);
}
public void doTestWiFiFallback(
final boolean cellRadioTimesharingCapable) throws Exception {
mService.mCellularRadioTimesharingCapable = cellRadioTimesharingCapable;
// Test bringing up unvalidated WiFi.
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
ExpectedBroadcast b = registerConnectivityBroadcast(1);