From ffc912dace5db15f957880b084d418db77ce310b Mon Sep 17 00:00:00 2001 From: Benedict Wong Date: Mon, 12 Apr 2021 23:42:59 -0700 Subject: [PATCH] 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 --- services/core/java/com/android/server/vcn/Vcn.java | 11 ++++++----- .../com/android/server/vcn/VcnGatewayConnection.java | 5 +++-- .../vcn/VcnGatewayConnectionConnectedStateTest.java | 10 +++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/vcn/Vcn.java b/services/core/java/com/android/server/vcn/Vcn.java index c7c538521de8e..cccb0968fc6ab 100644 --- a/services/core/java/com/android/server/vcn/Vcn.java +++ b/services/core/java/com/android/server/vcn/Vcn.java @@ -32,6 +32,7 @@ import android.content.ContentResolver; import android.database.ContentObserver; import android.net.NetworkCapabilities; import android.net.NetworkRequest; +import android.net.NetworkScore; import android.net.Uri; import android.net.vcn.VcnConfig; import android.net.vcn.VcnGatewayConnectionConfig; @@ -71,6 +72,8 @@ import java.util.Set; public class Vcn extends Handler { private static final String TAG = Vcn.class.getSimpleName(); + private static final int VCN_LEGACY_SCORE_INT = 52; + private static final List CAPS_REQUIRING_MOBILE_DATA = 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 */ - // Package visibility for use in VcnGatewayConnection - static int getNetworkScore() { - // TODO: STOPSHIP (b/173549607): Make this use new NetworkSelection, or some magic "max in - // subGrp" value - return 52; + // Package visibility for use in VcnGatewayConnection and VcnNetworkProvider + static NetworkScore getNetworkScore() { + return new NetworkScore.Builder().setLegacyInt(VCN_LEGACY_SCORE_INT).build(); } /** Callback used for passing status signals from a VcnGatewayConnection to its managing Vcn. */ diff --git a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java index 0765a0a43581b..23fb95b4fa404 100644 --- a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java +++ b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java @@ -49,6 +49,7 @@ import android.net.NetworkAgent; import android.net.NetworkAgentConfig; import android.net.NetworkCapabilities; import android.net.NetworkProvider; +import android.net.NetworkScore; import android.net.RouteInfo; import android.net.TelephonyNetworkSpecifier; import android.net.Uri; @@ -2203,7 +2204,7 @@ public class VcnGatewayConnection extends StateMachine { @NonNull String tag, @NonNull NetworkCapabilities caps, @NonNull LinkProperties lp, - @NonNull int score, + @NonNull NetworkScore score, @NonNull NetworkAgentConfig nac, @NonNull NetworkProvider provider, @NonNull Consumer networkUnwantedCallback, @@ -2344,7 +2345,7 @@ public class VcnGatewayConnection extends StateMachine { @NonNull String tag, @NonNull NetworkCapabilities caps, @NonNull LinkProperties lp, - @NonNull int score, + @NonNull NetworkScore score, @NonNull NetworkAgentConfig nac, @NonNull NetworkProvider provider, @NonNull Consumer networkUnwantedCallback, diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java index a2223e8c1e9ac..95a972652bf47 100644 --- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java +++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java @@ -89,7 +89,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection mNetworkAgent = mock(VcnNetworkAgent.class); doReturn(mNetworkAgent) .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); @@ -216,7 +216,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection any(), any(), any(), - anyInt(), + any(), any(), any(), any(), @@ -244,7 +244,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection any(String.class), ncCaptor.capture(), lpCaptor.capture(), - anyInt(), + any(), argThat(nac -> nac.getLegacyType() == ConnectivityManager.TYPE_MOBILE), any(), any(), @@ -297,7 +297,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection startingInternalAddrs.equals(lp.getLinkAddresses()) && Collections.singletonList(TEST_DNS_ADDR) .equals(lp.getDnsServers())), - anyInt(), + any(), any(), any(), any(), @@ -356,7 +356,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection any(), any(), any(), - anyInt(), + any(), any(), any(), unwantedCallbackCaptor.capture(),