enforce dedicated Wi-Fi for direct QR pairing

This commit is contained in:
zhy200308
2026-08-12 11:46:59 +08:00
parent eccd93266e
commit 65223dafe4
10 changed files with 345 additions and 306 deletions
@@ -4,6 +4,32 @@ import java.net.URI
/** Pure IPv4 routing helpers kept Android-free so candidate selection is testable. */
object EndpointRouting {
/**
* A dedicated QFT Wi-Fi must never reuse QR/LAN adapter addresses. Its only
* direct candidates are gateways supplied by Android for that exact Network.
* Current-LAN fallback mode may additionally use advertised same-subnet IPs.
*/
fun afterConnection(
dedicatedWifi: Boolean,
gatewayEndpoints: List<String>,
routedAdvertisedEndpoints: List<String>,
): List<String> = if (dedicatedWifi) {
gatewayEndpoints.distinct()
} else {
(gatewayEndpoints + routedAdvertisedEndpoints).distinct()
}
/** Same isolation rule for retry/recovery after the first gateway probe. */
fun forRecovery(
dedicatedWifi: Boolean,
discoveredEndpoint: String?,
gatewayEndpoints: List<String>,
advertisedEndpoints: List<String>,
): List<String> {
val candidates = listOfNotNull(discoveredEndpoint) + gatewayEndpoints
return (candidates + if (dedicatedWifi) emptyList() else advertisedEndpoints).distinct()
}
fun onAnySubnet(
endpoints: List<String>,
expectedPort: Int,