Loading services/core/java/com/android/server/connectivity/NetworkRanker.java +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public class NetworkRanker { NetworkCapabilities getCapsNoCopy(); } private static final boolean USE_POLICY_RANKING = false; private static final boolean USE_POLICY_RANKING = true; public NetworkRanker() { } Loading tests/net/java/com/android/server/ConnectivityServiceTest.java +3 −9 Original line number Diff line number Diff line Loading @@ -2974,15 +2974,9 @@ public class ConnectivityServiceTest { mEthernetNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_ETHERNET); mEthernetNetworkAgent.connect(true); // BUG: with the legacy int-based scoring code, the network will no longer linger, even // though it's validated and outscored. // The new policy-based scoring code fixes this. // TODO: remove the line below and replace with the three commented lines when // the policy-based scoring code is turned on. callback.expectAvailableThenValidatedCallbacks(mEthernetNetworkAgent); // callback.expectAvailableCallbacksUnvalidated(mEthernetNetworkAgent); // callback.expectCallback(CallbackEntry.LOSING, mWiFiNetworkAgent); // callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mEthernetNetworkAgent); callback.expectAvailableCallbacksUnvalidated(mEthernetNetworkAgent); callback.expectCallback(CallbackEntry.LOSING, mWiFiNetworkAgent); callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mEthernetNetworkAgent); assertEquals(mEthernetNetworkAgent.getNetwork(), mCm.getActiveNetwork()); callback.assertNoCallback(); Loading tests/net/java/com/android/server/connectivity/NetworkRankerTest.kt +10 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.server.connectivity import android.net.NetworkCapabilities import android.net.NetworkRequest import android.net.NetworkScore.KEEP_CONNECTED_NONE import androidx.test.filters.SmallTest import androidx.test.runner.AndroidJUnit4 import org.junit.Test Loading @@ -32,9 +34,13 @@ import kotlin.test.assertNull class NetworkRankerTest { private val ranker = NetworkRanker() private fun makeNai(satisfy: Boolean, score: Int) = mock(NetworkAgentInfo::class.java).also { private fun makeNai(satisfy: Boolean, legacyScore: Int) = mock(NetworkAgentInfo::class.java).also { doReturn(satisfy).`when`(it).satisfies(any()) doReturn(score).`when`(it).currentScore val fs = FullScore(legacyScore, 0 /* policies */, KEEP_CONNECTED_NONE) doReturn(fs).`when`(it).getScore() val nc = NetworkCapabilities.Builder().build() doReturn(nc).`when`(it).getCapsNoCopy() } @Test Loading Loading
services/core/java/com/android/server/connectivity/NetworkRanker.java +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public class NetworkRanker { NetworkCapabilities getCapsNoCopy(); } private static final boolean USE_POLICY_RANKING = false; private static final boolean USE_POLICY_RANKING = true; public NetworkRanker() { } Loading
tests/net/java/com/android/server/ConnectivityServiceTest.java +3 −9 Original line number Diff line number Diff line Loading @@ -2974,15 +2974,9 @@ public class ConnectivityServiceTest { mEthernetNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_ETHERNET); mEthernetNetworkAgent.connect(true); // BUG: with the legacy int-based scoring code, the network will no longer linger, even // though it's validated and outscored. // The new policy-based scoring code fixes this. // TODO: remove the line below and replace with the three commented lines when // the policy-based scoring code is turned on. callback.expectAvailableThenValidatedCallbacks(mEthernetNetworkAgent); // callback.expectAvailableCallbacksUnvalidated(mEthernetNetworkAgent); // callback.expectCallback(CallbackEntry.LOSING, mWiFiNetworkAgent); // callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mEthernetNetworkAgent); callback.expectAvailableCallbacksUnvalidated(mEthernetNetworkAgent); callback.expectCallback(CallbackEntry.LOSING, mWiFiNetworkAgent); callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mEthernetNetworkAgent); assertEquals(mEthernetNetworkAgent.getNetwork(), mCm.getActiveNetwork()); callback.assertNoCallback(); Loading
tests/net/java/com/android/server/connectivity/NetworkRankerTest.kt +10 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.server.connectivity import android.net.NetworkCapabilities import android.net.NetworkRequest import android.net.NetworkScore.KEEP_CONNECTED_NONE import androidx.test.filters.SmallTest import androidx.test.runner.AndroidJUnit4 import org.junit.Test Loading @@ -32,9 +34,13 @@ import kotlin.test.assertNull class NetworkRankerTest { private val ranker = NetworkRanker() private fun makeNai(satisfy: Boolean, score: Int) = mock(NetworkAgentInfo::class.java).also { private fun makeNai(satisfy: Boolean, legacyScore: Int) = mock(NetworkAgentInfo::class.java).also { doReturn(satisfy).`when`(it).satisfies(any()) doReturn(score).`when`(it).currentScore val fs = FullScore(legacyScore, 0 /* policies */, KEEP_CONNECTED_NONE) doReturn(fs).`when`(it).getScore() val nc = NetworkCapabilities.Builder().build() doReturn(nc).`when`(it).getCapsNoCopy() } @Test Loading