[VCN07] Bypass VCN for non-internet app accessible cellular services

Deduce the NET_CAPABILITY_NOT_VCN_MANAGED capability from other
capabilities and user intention, which includes:
   1. For the requests that don't have anything besides
      VCN_SUPPORTED_CAPABILITIES, add the NOT_VCN_MANAGED to
      allow the callers automatically utilize VCN networks
      if available.
   2. For the requests that explicitly add or remove
      NOT_VCN_MANAGED,  do not alter them to allow user fire
      request that suits their need.

Test: atest NetworkRequestTest#testBypassingVcnForNonInternetRequest
Bug: 175662146
Change-Id: I9936894b9530a22fb186cfd25cbee0fced65b72b
This commit is contained in:
junyulai
2021-01-13 18:13:11 +08:00
parent ab4b0cdccc
commit 2fc40da076
4 changed files with 84 additions and 9 deletions

View File

@@ -2590,6 +2590,10 @@ public class ConnectivityServiceTest {
NetworkCapabilities filter = new NetworkCapabilities();
filter.addCapability(capability);
// Add NOT_VCN_MANAGED capability into filter unconditionally since some request will add
// NOT_VCN_MANAGED automatically but not for NetworkCapabilities,
// see {@code NetworkCapabilities#deduceNotVcnManagedCapability} for more details.
filter.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED);
final HandlerThread handlerThread = new HandlerThread("testNetworkFactoryRequests");
handlerThread.start();
final MockNetworkFactory testFactory = new MockNetworkFactory(handlerThread.getLooper(),
@@ -3841,6 +3845,7 @@ public class ConnectivityServiceTest {
handlerThread.start();
NetworkCapabilities filter = new NetworkCapabilities()
.addTransportType(TRANSPORT_CELLULAR)
.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED)
.addCapability(NET_CAPABILITY_INTERNET);
final MockNetworkFactory testFactory = new MockNetworkFactory(handlerThread.getLooper(),
mServiceContext, "testFactory", filter);
@@ -5743,6 +5748,7 @@ public class ConnectivityServiceTest {
.addTransportType(TRANSPORT_CELLULAR)
.addCapability(NET_CAPABILITY_INTERNET)
.addCapability(NET_CAPABILITY_NOT_CONGESTED)
.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED)
.setLinkDownstreamBandwidthKbps(10);
final NetworkCapabilities wifiNc = new NetworkCapabilities()
.addTransportType(TRANSPORT_WIFI)
@@ -5751,6 +5757,7 @@ public class ConnectivityServiceTest {
.addCapability(NET_CAPABILITY_NOT_ROAMING)
.addCapability(NET_CAPABILITY_NOT_CONGESTED)
.addCapability(NET_CAPABILITY_NOT_SUSPENDED)
.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED)
.setLinkUpstreamBandwidthKbps(20);
mCellNetworkAgent.setNetworkCapabilities(cellNc, true /* sendToConnectivityService */);
mWiFiNetworkAgent.setNetworkCapabilities(wifiNc, true /* sendToConnectivityService */);
@@ -7382,19 +7389,13 @@ public class ConnectivityServiceTest {
mWiFiNetworkAgent.removeCapability(testCap);
callbackWithCap.expectAvailableCallbacksValidated(mCellNetworkAgent);
callbackWithoutCap.expectCapabilitiesWithout(testCap, mWiFiNetworkAgent);
// TODO: Test default network changes for NOT_VCN_MANAGED once the default request has
// it.
if (testCap == NET_CAPABILITY_TRUSTED) {
verify(mMockNetd).networkSetDefault(eq(mCellNetworkAgent.getNetwork().netId));
reset(mMockNetd);
}
verify(mMockNetd).networkSetDefault(eq(mCellNetworkAgent.getNetwork().netId));
reset(mMockNetd);
mCellNetworkAgent.removeCapability(testCap);
callbackWithCap.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
callbackWithoutCap.assertNoCallback();
if (testCap == NET_CAPABILITY_TRUSTED) {
verify(mMockNetd).networkClearDefault();
}
verify(mMockNetd).networkClearDefault();
mCm.unregisterNetworkCallback(callbackWithCap);
mCm.unregisterNetworkCallback(callbackWithoutCap);