Switch to using NetworkScore instead of legacy integer

This change switches the VcnNetworkAgent from using the legacy score
integer, and switches to using the new NetworkScore, using the legacy
integer as a internal representation.

Bug: 185204197
Test: FrameworksVcnTests
Change-Id: Ib0690243f176a2f074358fcc8430f1fd7c3d0d3c
This commit is contained in:
Benedict Wong
2021-04-12 23:42:59 -07:00
parent fff0f8ba33
commit ffc912dace
3 changed files with 14 additions and 12 deletions

View File

@@ -32,6 +32,7 @@ import android.content.ContentResolver;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkRequest; import android.net.NetworkRequest;
import android.net.NetworkScore;
import android.net.Uri; import android.net.Uri;
import android.net.vcn.VcnConfig; import android.net.vcn.VcnConfig;
import android.net.vcn.VcnGatewayConnectionConfig; import android.net.vcn.VcnGatewayConnectionConfig;
@@ -71,6 +72,8 @@ import java.util.Set;
public class Vcn extends Handler { public class Vcn extends Handler {
private static final String TAG = Vcn.class.getSimpleName(); private static final String TAG = Vcn.class.getSimpleName();
private static final int VCN_LEGACY_SCORE_INT = 52;
private static final List<Integer> CAPS_REQUIRING_MOBILE_DATA = private static final List<Integer> CAPS_REQUIRING_MOBILE_DATA =
Arrays.asList(NET_CAPABILITY_INTERNET, NET_CAPABILITY_DUN); Arrays.asList(NET_CAPABILITY_INTERNET, NET_CAPABILITY_DUN);
@@ -527,11 +530,9 @@ public class Vcn extends Handler {
} }
/** Retrieves the network score for a VCN Network */ /** Retrieves the network score for a VCN Network */
// Package visibility for use in VcnGatewayConnection // Package visibility for use in VcnGatewayConnection and VcnNetworkProvider
static int getNetworkScore() { static NetworkScore getNetworkScore() {
// TODO: STOPSHIP (b/173549607): Make this use new NetworkSelection, or some magic "max in return new NetworkScore.Builder().setLegacyInt(VCN_LEGACY_SCORE_INT).build();
// subGrp" value
return 52;
} }
/** Callback used for passing status signals from a VcnGatewayConnection to its managing Vcn. */ /** Callback used for passing status signals from a VcnGatewayConnection to its managing Vcn. */

View File

@@ -49,6 +49,7 @@ import android.net.NetworkAgent;
import android.net.NetworkAgentConfig; import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkProvider; import android.net.NetworkProvider;
import android.net.NetworkScore;
import android.net.RouteInfo; import android.net.RouteInfo;
import android.net.TelephonyNetworkSpecifier; import android.net.TelephonyNetworkSpecifier;
import android.net.Uri; import android.net.Uri;
@@ -2203,7 +2204,7 @@ public class VcnGatewayConnection extends StateMachine {
@NonNull String tag, @NonNull String tag,
@NonNull NetworkCapabilities caps, @NonNull NetworkCapabilities caps,
@NonNull LinkProperties lp, @NonNull LinkProperties lp,
@NonNull int score, @NonNull NetworkScore score,
@NonNull NetworkAgentConfig nac, @NonNull NetworkAgentConfig nac,
@NonNull NetworkProvider provider, @NonNull NetworkProvider provider,
@NonNull Consumer<VcnNetworkAgent> networkUnwantedCallback, @NonNull Consumer<VcnNetworkAgent> networkUnwantedCallback,
@@ -2344,7 +2345,7 @@ public class VcnGatewayConnection extends StateMachine {
@NonNull String tag, @NonNull String tag,
@NonNull NetworkCapabilities caps, @NonNull NetworkCapabilities caps,
@NonNull LinkProperties lp, @NonNull LinkProperties lp,
@NonNull int score, @NonNull NetworkScore score,
@NonNull NetworkAgentConfig nac, @NonNull NetworkAgentConfig nac,
@NonNull NetworkProvider provider, @NonNull NetworkProvider provider,
@NonNull Consumer<VcnNetworkAgent> networkUnwantedCallback, @NonNull Consumer<VcnNetworkAgent> networkUnwantedCallback,

View File

@@ -89,7 +89,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
mNetworkAgent = mock(VcnNetworkAgent.class); mNetworkAgent = mock(VcnNetworkAgent.class);
doReturn(mNetworkAgent) doReturn(mNetworkAgent)
.when(mDeps) .when(mDeps)
.newNetworkAgent(any(), any(), any(), any(), anyInt(), any(), any(), any(), any()); .newNetworkAgent(any(), any(), any(), any(), any(), any(), any(), any(), any());
mGatewayConnection.setUnderlyingNetwork(TEST_UNDERLYING_NETWORK_RECORD_1); mGatewayConnection.setUnderlyingNetwork(TEST_UNDERLYING_NETWORK_RECORD_1);
@@ -216,7 +216,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
any(), any(),
any(), any(),
any(), any(),
anyInt(), any(),
any(), any(),
any(), any(),
any(), any(),
@@ -244,7 +244,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
any(String.class), any(String.class),
ncCaptor.capture(), ncCaptor.capture(),
lpCaptor.capture(), lpCaptor.capture(),
anyInt(), any(),
argThat(nac -> nac.getLegacyType() == ConnectivityManager.TYPE_MOBILE), argThat(nac -> nac.getLegacyType() == ConnectivityManager.TYPE_MOBILE),
any(), any(),
any(), any(),
@@ -297,7 +297,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
startingInternalAddrs.equals(lp.getLinkAddresses()) startingInternalAddrs.equals(lp.getLinkAddresses())
&& Collections.singletonList(TEST_DNS_ADDR) && Collections.singletonList(TEST_DNS_ADDR)
.equals(lp.getDnsServers())), .equals(lp.getDnsServers())),
anyInt(), any(),
any(), any(),
any(), any(),
any(), any(),
@@ -356,7 +356,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
any(), any(),
any(), any(),
any(), any(),
anyInt(), any(),
any(), any(),
any(), any(),
unwantedCallbackCaptor.capture(), unwantedCallbackCaptor.capture(),