[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: I2876264cee14b624c89ba3b380027a8b521ad8ea
  (cherry-picked from aosp/1549817)
This commit is contained in:
junyulai
2021-01-13 18:13:11 +08:00
parent b30d38f3ef
commit 719814c97a
4 changed files with 84 additions and 9 deletions

View File

@@ -2761,6 +2761,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(),
@@ -4120,6 +4124,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);
@@ -6023,6 +6028,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)
@@ -6031,6 +6037,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 */);
@@ -7718,19 +7725,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);