Merge changes I1cf472bd,Ibdaf2b23,I6967ad6f,I65f522c2,I0f220d1f, ... am: a3340c1355
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2001790 Change-Id: I1ab803bf751ef4dcb76c07d71ff6acd7873a2b60 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -18,6 +18,8 @@ package com.android.server.connectivity
|
||||
|
||||
import android.net.NetworkAgentConfig
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkScore
|
||||
import android.net.NetworkScore.KEEP_CONNECTED_FOR_HANDOVER
|
||||
import android.net.NetworkScore.KEEP_CONNECTED_NONE
|
||||
import android.os.Build
|
||||
import android.text.TextUtils
|
||||
@@ -25,6 +27,7 @@ import android.util.ArraySet
|
||||
import android.util.Log
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.server.connectivity.FullScore.MAX_CS_MANAGED_POLICY
|
||||
import com.android.server.connectivity.FullScore.MIN_CS_MANAGED_POLICY
|
||||
import com.android.server.connectivity.FullScore.POLICY_ACCEPT_UNVALIDATED
|
||||
import com.android.server.connectivity.FullScore.POLICY_EVER_USER_SELECTED
|
||||
import com.android.server.connectivity.FullScore.POLICY_IS_DESTROYED
|
||||
@@ -40,6 +43,7 @@ import org.junit.runner.RunWith
|
||||
import kotlin.reflect.full.staticProperties
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@RunWith(DevSdkIgnoreRunner::class)
|
||||
@@ -82,34 +86,11 @@ class FullScoreTest {
|
||||
Log.setWtfHandler(wtfHandler)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetLegacyInt() {
|
||||
val ns = FullScore(50, 0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
assertEquals(10, ns.legacyInt) // -40 penalty for not being validated
|
||||
assertEquals(50, ns.legacyIntAsValidated)
|
||||
|
||||
val vpnNs = FullScore(101, 0L /* policy */, KEEP_CONNECTED_NONE).withPolicies(vpn = true)
|
||||
assertEquals(101, vpnNs.legacyInt) // VPNs are not subject to unvalidation penalty
|
||||
assertEquals(101, vpnNs.legacyIntAsValidated)
|
||||
assertEquals(101, vpnNs.withPolicies(validated = true).legacyInt)
|
||||
assertEquals(101, vpnNs.withPolicies(validated = true).legacyIntAsValidated)
|
||||
|
||||
val validatedNs = ns.withPolicies(validated = true)
|
||||
assertEquals(50, validatedNs.legacyInt) // No penalty, this is validated
|
||||
assertEquals(50, validatedNs.legacyIntAsValidated)
|
||||
|
||||
val chosenNs = ns.withPolicies(onceChosen = true)
|
||||
assertEquals(10, chosenNs.legacyInt)
|
||||
assertEquals(100, chosenNs.legacyIntAsValidated)
|
||||
assertEquals(10, chosenNs.withPolicies(acceptUnvalidated = true).legacyInt)
|
||||
assertEquals(50, chosenNs.withPolicies(acceptUnvalidated = true).legacyIntAsValidated)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
val string = FullScore(10, 0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
val string = FullScore(0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
.withPolicies(vpn = true, acceptUnvalidated = true).toString()
|
||||
assertTrue(string.contains("Score(10"), string)
|
||||
assertTrue(string.contains("Score("), string)
|
||||
assertTrue(string.contains("ACCEPT_UNVALIDATED"), string)
|
||||
assertTrue(string.contains("IS_VPN"), string)
|
||||
assertFalse(string.contains("IS_VALIDATED"), string)
|
||||
@@ -131,7 +112,7 @@ class FullScoreTest {
|
||||
|
||||
@Test
|
||||
fun testHasPolicy() {
|
||||
val ns = FullScore(50, 0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
val ns = FullScore(0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
assertFalse(ns.hasPolicy(POLICY_IS_VALIDATED))
|
||||
assertFalse(ns.hasPolicy(POLICY_IS_VPN))
|
||||
assertFalse(ns.hasPolicy(POLICY_EVER_USER_SELECTED))
|
||||
@@ -148,12 +129,23 @@ class FullScoreTest {
|
||||
val policies = getAllPolicies()
|
||||
|
||||
policies.forEach { policy ->
|
||||
assertTrue(policy.get() as Int >= FullScore.MIN_CS_MANAGED_POLICY)
|
||||
assertTrue(policy.get() as Int <= FullScore.MAX_CS_MANAGED_POLICY)
|
||||
assertTrue(policy.get() as Int >= MIN_CS_MANAGED_POLICY)
|
||||
assertTrue(policy.get() as Int <= MAX_CS_MANAGED_POLICY)
|
||||
}
|
||||
assertEquals(FullScore.MIN_CS_MANAGED_POLICY,
|
||||
policies.minOfOrNull { it.get() as Int })
|
||||
assertEquals(FullScore.MAX_CS_MANAGED_POLICY,
|
||||
policies.maxOfOrNull { it.get() as Int })
|
||||
assertEquals(MIN_CS_MANAGED_POLICY, policies.minOfOrNull { it.get() as Int })
|
||||
assertEquals(MAX_CS_MANAGED_POLICY, policies.maxOfOrNull { it.get() as Int })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
val ns1 = FullScore(0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
val ns2 = FullScore(0L /* policy */, KEEP_CONNECTED_NONE)
|
||||
val ns3 = FullScore(0L /* policy */, KEEP_CONNECTED_FOR_HANDOVER)
|
||||
val ns4 = NetworkScore.Builder().setLegacyInt(50).build()
|
||||
assertEquals(ns1, ns1)
|
||||
assertEquals(ns2, ns1)
|
||||
assertNotEquals(ns1.withPolicies(validated = true), ns1)
|
||||
assertNotEquals(ns3, ns1)
|
||||
assertFalse(ns1.equals(ns4))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,18 +138,16 @@ public class IpConnectivityMetricsTest {
|
||||
private void logDefaultNetworkEvent(long timeMs, NetworkAgentInfo nai,
|
||||
NetworkAgentInfo oldNai) {
|
||||
final Network network = (nai != null) ? nai.network() : null;
|
||||
final int score = (nai != null) ? nai.getCurrentScore() : 0;
|
||||
final boolean validated = (nai != null) ? nai.lastValidated : false;
|
||||
final LinkProperties lp = (nai != null) ? nai.linkProperties : null;
|
||||
final NetworkCapabilities nc = (nai != null) ? nai.networkCapabilities : null;
|
||||
|
||||
final Network prevNetwork = (oldNai != null) ? oldNai.network() : null;
|
||||
final int prevScore = (oldNai != null) ? oldNai.getCurrentScore() : 0;
|
||||
final LinkProperties prevLp = (oldNai != null) ? oldNai.linkProperties : null;
|
||||
final NetworkCapabilities prevNc = (oldNai != null) ? oldNai.networkCapabilities : null;
|
||||
|
||||
mService.mDefaultNetworkMetrics.logDefaultNetworkEvent(timeMs, network, score, validated,
|
||||
lp, nc, prevNetwork, prevScore, prevLp, prevNc);
|
||||
mService.mDefaultNetworkMetrics.logDefaultNetworkEvent(timeMs, network, 0 /* legacyScore */,
|
||||
validated, lp, nc, prevNetwork, 0 /* prevLegacyScore */, prevLp, prevNc);
|
||||
}
|
||||
@Test
|
||||
public void testDefaultNetworkEvents() throws Exception {
|
||||
@@ -158,15 +156,15 @@ public class IpConnectivityMetricsTest {
|
||||
|
||||
NetworkAgentInfo[][] defaultNetworks = {
|
||||
// nothing -> cell
|
||||
{null, makeNai(100, 10, false, true, cell)},
|
||||
{null, makeNai(100, false, true, cell)},
|
||||
// cell -> wifi
|
||||
{makeNai(100, 50, true, true, cell), makeNai(101, 20, true, false, wifi)},
|
||||
{makeNai(100, true, true, cell), makeNai(101, true, false, wifi)},
|
||||
// wifi -> nothing
|
||||
{makeNai(101, 60, true, false, wifi), null},
|
||||
{makeNai(101, true, false, wifi), null},
|
||||
// nothing -> cell
|
||||
{null, makeNai(102, 10, true, true, cell)},
|
||||
{null, makeNai(102, true, true, cell)},
|
||||
// cell -> wifi
|
||||
{makeNai(102, 50, true, true, cell), makeNai(103, 20, true, false, wifi)},
|
||||
{makeNai(102, true, true, cell), makeNai(103, true, false, wifi)},
|
||||
};
|
||||
|
||||
long timeMs = mService.mDefaultNetworkMetrics.creationTimeMs;
|
||||
@@ -204,8 +202,8 @@ public class IpConnectivityMetricsTest {
|
||||
" transports: 1",
|
||||
" default_network_event <",
|
||||
" default_network_duration_ms: 2002",
|
||||
" final_score: 50",
|
||||
" initial_score: 10",
|
||||
" final_score: 0",
|
||||
" initial_score: 0",
|
||||
" ip_support: 3",
|
||||
" no_default_network_duration_ms: 0",
|
||||
" previous_default_network_link_layer: 0",
|
||||
@@ -221,8 +219,8 @@ public class IpConnectivityMetricsTest {
|
||||
" transports: 2",
|
||||
" default_network_event <",
|
||||
" default_network_duration_ms: 4004",
|
||||
" final_score: 60",
|
||||
" initial_score: 20",
|
||||
" final_score: 0",
|
||||
" initial_score: 0",
|
||||
" ip_support: 1",
|
||||
" no_default_network_duration_ms: 0",
|
||||
" previous_default_network_link_layer: 2",
|
||||
@@ -255,8 +253,8 @@ public class IpConnectivityMetricsTest {
|
||||
" transports: 1",
|
||||
" default_network_event <",
|
||||
" default_network_duration_ms: 16016",
|
||||
" final_score: 50",
|
||||
" initial_score: 10",
|
||||
" final_score: 0",
|
||||
" initial_score: 0",
|
||||
" ip_support: 3",
|
||||
" no_default_network_duration_ms: 0",
|
||||
" previous_default_network_link_layer: 4",
|
||||
@@ -348,8 +346,8 @@ public class IpConnectivityMetricsTest {
|
||||
long timeMs = mService.mDefaultNetworkMetrics.creationTimeMs;
|
||||
final long cell = BitUtils.packBits(new int[]{NetworkCapabilities.TRANSPORT_CELLULAR});
|
||||
final long wifi = BitUtils.packBits(new int[]{NetworkCapabilities.TRANSPORT_WIFI});
|
||||
NetworkAgentInfo cellNai = makeNai(100, 50, false, true, cell);
|
||||
NetworkAgentInfo wifiNai = makeNai(101, 60, true, false, wifi);
|
||||
final NetworkAgentInfo cellNai = makeNai(100, false, true, cell);
|
||||
final NetworkAgentInfo wifiNai = makeNai(101, true, false, wifi);
|
||||
logDefaultNetworkEvent(timeMs + 200L, cellNai, null);
|
||||
logDefaultNetworkEvent(timeMs + 300L, wifiNai, cellNai);
|
||||
|
||||
@@ -463,8 +461,8 @@ public class IpConnectivityMetricsTest {
|
||||
" transports: 1",
|
||||
" default_network_event <",
|
||||
" default_network_duration_ms: 100",
|
||||
" final_score: 50",
|
||||
" initial_score: 50",
|
||||
" final_score: 0",
|
||||
" initial_score: 0",
|
||||
" ip_support: 2",
|
||||
" no_default_network_duration_ms: 0",
|
||||
" previous_default_network_link_layer: 0",
|
||||
@@ -611,10 +609,9 @@ public class IpConnectivityMetricsTest {
|
||||
mNetdListener.onWakeupEvent(prefix, uid, ether, ip, mac, srcIp, dstIp, sport, dport, now);
|
||||
}
|
||||
|
||||
NetworkAgentInfo makeNai(int netId, int score, boolean ipv4, boolean ipv6, long transports) {
|
||||
NetworkAgentInfo makeNai(int netId, boolean ipv4, boolean ipv6, long transports) {
|
||||
NetworkAgentInfo nai = mock(NetworkAgentInfo.class);
|
||||
when(nai.network()).thenReturn(new Network(netId));
|
||||
when(nai.getCurrentScore()).thenReturn(score);
|
||||
nai.linkProperties = new LinkProperties();
|
||||
nai.networkCapabilities = new NetworkCapabilities();
|
||||
nai.lastValidated = true;
|
||||
|
||||
@@ -42,7 +42,7 @@ class NetworkOfferTest {
|
||||
|
||||
@Test
|
||||
fun testOfferNeededUnneeded() {
|
||||
val score = FullScore(50, POLICY_NONE, KEEP_CONNECTED_NONE)
|
||||
val score = FullScore(POLICY_NONE, KEEP_CONNECTED_NONE)
|
||||
val offer = NetworkOffer(score, NetworkCapabilities.Builder().build(), mockCallback,
|
||||
1 /* providerId */)
|
||||
val request1 = mock(NetworkRequest::class.java)
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
private fun score(vararg policies: Int) = FullScore(0,
|
||||
private fun score(vararg policies: Int) = FullScore(
|
||||
policies.fold(0L) { acc, e -> acc or (1L shl e) }, KEEP_CONNECTED_NONE)
|
||||
private fun caps(transport: Int) = NetworkCapabilities.Builder().addTransportType(transport).build()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user