Enable policy ranking

Test: Passes all presubmits, been tested in labs
Bug: 184834350
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: If33884aa245bcc8817bbc9c2fdfab035249e7301
Change-Id: If33884aa245bcc8817bbc9c2fdfab035249e7301
  (cherry-picked from ag/14150470)
This commit is contained in:
Chalard Jean
2021-04-12 17:16:04 +09:00
committed by Junyu Lai
parent a95eef727e
commit f4c48a4d5f
3 changed files with 14 additions and 14 deletions

View File

@@ -63,7 +63,7 @@ public class NetworkRanker {
NetworkCapabilities getCapsNoCopy(); NetworkCapabilities getCapsNoCopy();
} }
private static final boolean USE_POLICY_RANKING = false; private static final boolean USE_POLICY_RANKING = true;
public NetworkRanker() { } public NetworkRanker() { }

View File

@@ -3000,15 +3000,9 @@ public class ConnectivityServiceTest {
mEthernetNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_ETHERNET); mEthernetNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_ETHERNET);
mEthernetNetworkAgent.connect(true); mEthernetNetworkAgent.connect(true);
// BUG: with the legacy int-based scoring code, the network will no longer linger, even callback.expectAvailableCallbacksUnvalidated(mEthernetNetworkAgent);
// though it's validated and outscored. callback.expectCallback(CallbackEntry.LOSING, mWiFiNetworkAgent);
// The new policy-based scoring code fixes this. callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mEthernetNetworkAgent);
// 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);
assertEquals(mEthernetNetworkAgent.getNetwork(), mCm.getActiveNetwork()); assertEquals(mEthernetNetworkAgent.getNetwork(), mCm.getActiveNetwork());
callback.assertNoCallback(); callback.assertNoCallback();

View File

@@ -16,7 +16,9 @@
package com.android.server.connectivity package com.android.server.connectivity
import android.net.NetworkCapabilities
import android.net.NetworkRequest import android.net.NetworkRequest
import android.net.NetworkScore.KEEP_CONNECTED_NONE
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4 import androidx.test.runner.AndroidJUnit4
import org.junit.Test import org.junit.Test
@@ -32,10 +34,14 @@ import kotlin.test.assertNull
class NetworkRankerTest { class NetworkRankerTest {
private val ranker = NetworkRanker() private val ranker = NetworkRanker()
private fun makeNai(satisfy: Boolean, score: Int) = mock(NetworkAgentInfo::class.java).also { private fun makeNai(satisfy: Boolean, legacyScore: Int) =
doReturn(satisfy).`when`(it).satisfies(any()) mock(NetworkAgentInfo::class.java).also {
doReturn(score).`when`(it).currentScore doReturn(satisfy).`when`(it).satisfies(any())
} 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 @Test
fun testGetBestNetwork() { fun testGetBestNetwork() {