Merge "Add methods to support verifying captive portal launch" into main

This commit is contained in:
Chiachang Wang 2024-02-26 06:02:42 +00:00 • committed by Gerrit Code Review
commit 3023965cf8

View file

@ -19,6 +19,8 @@ package com.android.server
import android.content.Context
import android.net.ConnectivityManager
import android.net.INetworkMonitor
import android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_DNS
import android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTP
import android.net.INetworkMonitorCallbacks
import android.net.LinkProperties
import android.net.LocalNetworkConfig
@ -75,10 +77,15 @@ class CSAgentWrapper(
) : TestableNetworkCallback.HasNetwork {
private val TAG = "CSAgent${nextAgentId()}"
private val VALIDATION_RESULT_INVALID = 0
private val NO_PROBE_RESULT = 0
private val VALIDATION_TIMESTAMP = 1234L
private val agent: NetworkAgent
private val nmCallbacks: INetworkMonitorCallbacks
val networkMonitor = mock<INetworkMonitor>()
private var nmValidationRedirectUrl: String? = null
private var nmValidationResult = NO_PROBE_RESULT
private var nmProbesCompleted = NO_PROBE_RESULT
private var nmProbesSucceeded = NO_PROBE_RESULT
override val network: Network get() = agent.network!!
@ -120,10 +127,10 @@ class CSAgentWrapper(
}
nmCallbacks.notifyProbeStatusChanged(0 /* completed */, 0 /* succeeded */)
val p = NetworkTestResultParcelable()
p.result = VALIDATION_RESULT_INVALID
p.probesAttempted = 0
p.probesSucceeded = 0
p.redirectUrl = null
p.result = nmValidationResult
p.probesAttempted = nmProbesCompleted
p.probesSucceeded = nmProbesSucceeded
p.redirectUrl = nmValidationRedirectUrl
p.timestampMillis = VALIDATION_TIMESTAMP
nmCallbacks.notifyNetworkTestedWithExtras(p)
}
@ -171,4 +178,26 @@ class CSAgentWrapper(
fun sendLocalNetworkConfig(lnc: LocalNetworkConfig) = agent.sendLocalNetworkConfig(lnc)
fun sendNetworkCapabilities(nc: NetworkCapabilities) = agent.sendNetworkCapabilities(nc)
fun connectWithCaptivePortal(redirectUrl: String) {
setCaptivePortal(redirectUrl)
connect()
}
fun setProbesStatus(probesCompleted: Int, probesSucceeded: Int) {
nmProbesCompleted = probesCompleted
nmProbesSucceeded = probesSucceeded
}
fun setCaptivePortal(redirectUrl: String) {
nmValidationResult = VALIDATION_RESULT_INVALID
nmValidationRedirectUrl = redirectUrl
// Suppose the portal is found when NetworkMonitor probes NETWORK_VALIDATION_PROBE_HTTP
// in the beginning. Because NETWORK_VALIDATION_PROBE_HTTP is the decisive probe for captive
// portal, considering the NETWORK_VALIDATION_PROBE_HTTPS hasn't probed yet and set only
// DNS and HTTP probes completed.
setProbesStatus(
NETWORK_VALIDATION_PROBE_DNS or NETWORK_VALIDATION_PROBE_HTTP /* probesCompleted */,
VALIDATION_RESULT_INVALID /* probesSucceeded */)
}
}