Use FromS() on LocalNetworkConfig
Like NetworkScore, this object is not available on R because of the absence of the tethering module. Therefore it needs to be wrapped to be protected against introspection by the test libraries. Change-Id: Ia5f84d2926433398cef33d89819a8c6588024ea0 Test: FrameworkNetTests
This commit is contained in:
@@ -47,8 +47,9 @@ class CSKeepConnectedTest : CSTest() {
|
|||||||
val keepConnectedAgent = Agent(nc = nc, score = FromS(NetworkScore.Builder()
|
val keepConnectedAgent = Agent(nc = nc, score = FromS(NetworkScore.Builder()
|
||||||
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
||||||
.build()),
|
.build()),
|
||||||
lnc = LocalNetworkConfig.Builder().build())
|
lnc = FromS(LocalNetworkConfig.Builder().build()))
|
||||||
val dontKeepConnectedAgent = Agent(nc = nc, lnc = LocalNetworkConfig.Builder().build())
|
val dontKeepConnectedAgent = Agent(nc = nc,
|
||||||
|
lnc = FromS(LocalNetworkConfig.Builder().build()))
|
||||||
doTestKeepConnected(keepConnectedAgent, dontKeepConnectedAgent)
|
doTestKeepConnected(keepConnectedAgent, dontKeepConnectedAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ private const val NO_CALLBACK_TIMEOUT_MS = 200L
|
|||||||
private fun keepConnectedScore() =
|
private fun keepConnectedScore() =
|
||||||
FromS(NetworkScore.Builder().setKeepConnectedReason(KEEP_CONNECTED_FOR_TEST).build())
|
FromS(NetworkScore.Builder().setKeepConnectedReason(KEEP_CONNECTED_FOR_TEST).build())
|
||||||
|
|
||||||
private fun defaultLnc() = LocalNetworkConfig.Builder().build()
|
private fun defaultLnc() = FromS(LocalNetworkConfig.Builder().build())
|
||||||
|
|
||||||
@RunWith(DevSdkIgnoreRunner::class)
|
@RunWith(DevSdkIgnoreRunner::class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@@ -124,8 +124,7 @@ class CSLocalAgentCreationTests(
|
|||||||
lnc = null)
|
lnc = null)
|
||||||
}
|
}
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
Agent(nc = NetworkCapabilities.Builder().build(),
|
Agent(nc = NetworkCapabilities.Builder().build(), lnc = defaultLnc())
|
||||||
lnc = LocalNetworkConfig.Builder().build())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
}
|
}
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
Agent(nc = NetworkCapabilities.Builder().build(),
|
Agent(nc = NetworkCapabilities.Builder().build(),
|
||||||
lnc = LocalNetworkConfig.Builder().build())
|
lnc = FromS(LocalNetworkConfig.Builder().build()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
val agent = Agent(nc = NetworkCapabilities.Builder()
|
val agent = Agent(nc = NetworkCapabilities.Builder()
|
||||||
.addCapability(NET_CAPABILITY_LOCAL_NETWORK)
|
.addCapability(NET_CAPABILITY_LOCAL_NETWORK)
|
||||||
.build(),
|
.build(),
|
||||||
lnc = LocalNetworkConfig.Builder().build())
|
lnc = FromS(LocalNetworkConfig.Builder().build()))
|
||||||
agent.connect()
|
agent.connect()
|
||||||
cb.expectAvailableCallbacks(agent.network, validated = false)
|
cb.expectAvailableCallbacks(agent.network, validated = false)
|
||||||
agent.sendNetworkCapabilities(NetworkCapabilities.Builder().build())
|
agent.sendNetworkCapabilities(NetworkCapabilities.Builder().build())
|
||||||
@@ -141,7 +141,7 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
val localAgent = Agent(
|
val localAgent = Agent(
|
||||||
nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
||||||
lp = lp("local0"),
|
lp = lp("local0"),
|
||||||
lnc = LocalNetworkConfig.Builder().build(),
|
lnc = FromS(LocalNetworkConfig.Builder().build()),
|
||||||
)
|
)
|
||||||
localAgent.connect()
|
localAgent.connect()
|
||||||
|
|
||||||
@@ -194,11 +194,11 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
// Set up a local agent that should forward its traffic to the best wifi upstream.
|
// Set up a local agent that should forward its traffic to the best wifi upstream.
|
||||||
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
||||||
lp = lp("local0"),
|
lp = lp("local0"),
|
||||||
lnc = LocalNetworkConfig.Builder()
|
lnc = FromS(LocalNetworkConfig.Builder()
|
||||||
.setUpstreamSelector(NetworkRequest.Builder()
|
.setUpstreamSelector(NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI)
|
.addTransportType(TRANSPORT_WIFI)
|
||||||
.build())
|
.build())
|
||||||
.build(),
|
.build()),
|
||||||
score = FromS(NetworkScore.Builder()
|
score = FromS(NetworkScore.Builder()
|
||||||
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
||||||
.build())
|
.build())
|
||||||
@@ -247,11 +247,11 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
// Set up a local agent that should forward its traffic to the best wifi upstream.
|
// Set up a local agent that should forward its traffic to the best wifi upstream.
|
||||||
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
||||||
lp = lp("local0"),
|
lp = lp("local0"),
|
||||||
lnc = LocalNetworkConfig.Builder()
|
lnc = FromS(LocalNetworkConfig.Builder()
|
||||||
.setUpstreamSelector(NetworkRequest.Builder()
|
.setUpstreamSelector(NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI)
|
.addTransportType(TRANSPORT_WIFI)
|
||||||
.build())
|
.build())
|
||||||
.build(),
|
.build()),
|
||||||
score = FromS(NetworkScore.Builder()
|
score = FromS(NetworkScore.Builder()
|
||||||
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
||||||
.build())
|
.build())
|
||||||
@@ -293,11 +293,11 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
cm.registerNetworkCallback(NetworkRequest.Builder().clearCapabilities().build(), cb)
|
cm.registerNetworkCallback(NetworkRequest.Builder().clearCapabilities().build(), cb)
|
||||||
|
|
||||||
val localNc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK)
|
val localNc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK)
|
||||||
val lnc = LocalNetworkConfig.Builder()
|
val lnc = FromS(LocalNetworkConfig.Builder()
|
||||||
.setUpstreamSelector(NetworkRequest.Builder()
|
.setUpstreamSelector(NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI)
|
.addTransportType(TRANSPORT_WIFI)
|
||||||
.build())
|
.build())
|
||||||
.build()
|
.build())
|
||||||
val localScore = FromS(NetworkScore.Builder().build())
|
val localScore = FromS(NetworkScore.Builder().build())
|
||||||
|
|
||||||
// Set up a local agent that should forward its traffic to the best wifi upstream.
|
// Set up a local agent that should forward its traffic to the best wifi upstream.
|
||||||
@@ -346,11 +346,11 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
wifiAgent.unregisterAfterReplacement(LONG_TIMEOUT_MS)
|
wifiAgent.unregisterAfterReplacement(LONG_TIMEOUT_MS)
|
||||||
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
||||||
lp = lp("local0"),
|
lp = lp("local0"),
|
||||||
lnc = LocalNetworkConfig.Builder()
|
lnc = FromS(LocalNetworkConfig.Builder()
|
||||||
.setUpstreamSelector(NetworkRequest.Builder()
|
.setUpstreamSelector(NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI)
|
.addTransportType(TRANSPORT_WIFI)
|
||||||
.build())
|
.build())
|
||||||
.build(),
|
.build()),
|
||||||
score = FromS(NetworkScore.Builder()
|
score = FromS(NetworkScore.Builder()
|
||||||
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
.setKeepConnectedReason(KEEP_CONNECTED_LOCAL_NETWORK)
|
||||||
.build())
|
.build())
|
||||||
@@ -374,11 +374,11 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
fun testForwardingRules() {
|
fun testForwardingRules() {
|
||||||
deps.setBuildSdk(VERSION_V)
|
deps.setBuildSdk(VERSION_V)
|
||||||
// Set up a local agent that should forward its traffic to the best DUN upstream.
|
// Set up a local agent that should forward its traffic to the best DUN upstream.
|
||||||
val lnc = LocalNetworkConfig.Builder()
|
val lnc = FromS(LocalNetworkConfig.Builder()
|
||||||
.setUpstreamSelector(NetworkRequest.Builder()
|
.setUpstreamSelector(NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_DUN)
|
.addCapability(NET_CAPABILITY_DUN)
|
||||||
.build())
|
.build())
|
||||||
.build()
|
.build())
|
||||||
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
val localAgent = Agent(nc = nc(TRANSPORT_WIFI, NET_CAPABILITY_LOCAL_NETWORK),
|
||||||
lp = lp("local0"),
|
lp = lp("local0"),
|
||||||
lnc = lnc,
|
lnc = lnc,
|
||||||
@@ -426,7 +426,7 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
|
|
||||||
// Make sure sending the same config again doesn't do anything
|
// Make sure sending the same config again doesn't do anything
|
||||||
repeat(5) {
|
repeat(5) {
|
||||||
localAgent.sendLocalNetworkConfig(lnc)
|
localAgent.sendLocalNetworkConfig(lnc.value)
|
||||||
}
|
}
|
||||||
inOrder.verifyNoMoreInteractions()
|
inOrder.verifyNoMoreInteractions()
|
||||||
|
|
||||||
@@ -501,13 +501,13 @@ class CSLocalAgentTests : CSTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up a local agent.
|
// Set up a local agent.
|
||||||
val lnc = LocalNetworkConfig.Builder().apply {
|
val lnc = FromS(LocalNetworkConfig.Builder().apply {
|
||||||
if (haveUpstream) {
|
if (haveUpstream) {
|
||||||
setUpstreamSelector(NetworkRequest.Builder()
|
setUpstreamSelector(NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI)
|
.addTransportType(TRANSPORT_WIFI)
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
}.build()
|
}.build())
|
||||||
val localAgent = Agent(nc = nc(TRANSPORT_THREAD, NET_CAPABILITY_LOCAL_NETWORK),
|
val localAgent = Agent(nc = nc(TRANSPORT_THREAD, NET_CAPABILITY_LOCAL_NETWORK),
|
||||||
lp = lp("local0"),
|
lp = lp("local0"),
|
||||||
lnc = lnc,
|
lnc = lnc,
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class CSAgentWrapper(
|
|||||||
nac: NetworkAgentConfig,
|
nac: NetworkAgentConfig,
|
||||||
val nc: NetworkCapabilities,
|
val nc: NetworkCapabilities,
|
||||||
val lp: LinkProperties,
|
val lp: LinkProperties,
|
||||||
val lnc: LocalNetworkConfig?,
|
val lnc: FromS<LocalNetworkConfig>?,
|
||||||
val score: FromS<NetworkScore>,
|
val score: FromS<NetworkScore>,
|
||||||
val provider: NetworkProvider?
|
val provider: NetworkProvider?
|
||||||
) : TestableNetworkCallback.HasNetwork {
|
) : TestableNetworkCallback.HasNetwork {
|
||||||
@@ -101,7 +101,7 @@ class CSAgentWrapper(
|
|||||||
// Create the actual agent. NetworkAgent is abstract, so make an anonymous subclass.
|
// Create the actual agent. NetworkAgent is abstract, so make an anonymous subclass.
|
||||||
if (deps.isAtLeastS()) {
|
if (deps.isAtLeastS()) {
|
||||||
agent = object : NetworkAgent(context, csHandlerThread.looper, TAG,
|
agent = object : NetworkAgent(context, csHandlerThread.looper, TAG,
|
||||||
nc, lp, lnc, score.value, nac, provider) {}
|
nc, lp, lnc?.value, score.value, nac, provider) {}
|
||||||
} else {
|
} else {
|
||||||
agent = object : NetworkAgent(context, csHandlerThread.looper, TAG,
|
agent = object : NetworkAgent(context, csHandlerThread.looper, TAG,
|
||||||
nc, lp, 50 /* score */, nac, provider) {}
|
nc, lp, 50 /* score */, nac, provider) {}
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ open class CSTest {
|
|||||||
nc: NetworkCapabilities = defaultNc(),
|
nc: NetworkCapabilities = defaultNc(),
|
||||||
nac: NetworkAgentConfig = emptyAgentConfig(nc.getLegacyType()),
|
nac: NetworkAgentConfig = emptyAgentConfig(nc.getLegacyType()),
|
||||||
lp: LinkProperties = defaultLp(),
|
lp: LinkProperties = defaultLp(),
|
||||||
lnc: LocalNetworkConfig? = null,
|
lnc: FromS<LocalNetworkConfig>? = null,
|
||||||
score: FromS<NetworkScore> = defaultScore(),
|
score: FromS<NetworkScore> = defaultScore(),
|
||||||
provider: NetworkProvider? = null
|
provider: NetworkProvider? = null
|
||||||
) = CSAgentWrapper(context, deps, csHandlerThread, networkStack,
|
) = CSAgentWrapper(context, deps, csHandlerThread, networkStack,
|
||||||
|
|||||||
Reference in New Issue
Block a user