fix(android): pass PROTOCOL_DNS_SD so mDNS registration works

Android 16 added NsdManager.checkProtocol(): registerService with protocol
0 threw IllegalArgumentException: Unsupported protocol — silently, since
the old code swallowed the exception into a dead reflection fallback and
start() overwrote the failure status with the Listening line. mDNS never
actually advertised (the Phase 8 session streamed via --peer, masking it).

Also advertise after the listening status so a registration failure stays
visible, and log the exception and the registration success.

Validated live on the Fairphone 6: the desktop --discover lists the phone
and a full --send session decodes (in-band SPS 320x240 -> 2496x1040) and
renders.
This commit is contained in:
2026-09-10 12:35:00 +02:00
parent c6722d164b
commit 9a24933203
4 changed files with 53 additions and 2 deletions
@@ -110,11 +110,13 @@ class ReceiverPipeline(
running = true
readerThread = Thread({ readLoop() }, "rtp-reader").also { it.start() }
advertiseNsd(signalingPort)
// Advertise AFTER the listening status: a registration failure must
// not be overwritten by it (both post to the same overlay).
onStatus(
"Listening on $localIp (media :$udpPort, signaling :$signalingPort)\n" +
"Waiting for a sender… (fall back to: screencast --send --peer $localIp:$signalingPort)",
)
advertiseNsd(signalingPort)
}
/**
@@ -345,6 +347,7 @@ class ReceiverPipeline(
val listener = object : NsdManager.RegistrationListener {
override fun onServiceRegistered(serviceInfo: NsdServiceInfo) {
// Registered: the sender's mDNS browser should see it now.
android.util.Log.i(TAG, "mDNS registered: ${serviceInfo.serviceName}.${SERVICE_TYPE}")
}
override fun onServiceUnregistered(serviceInfo: NsdServiceInfo) = Unit
@@ -356,9 +359,14 @@ class ReceiverPipeline(
override fun onUnregistrationFailed(serviceInfo: NsdServiceInfo, errorCode: Int) = Unit
}
try {
nsdManager.registerService(info, 0, listener)
// PROTOCOL_DNS_SD is mandatory on API 36: NsdManager.checkProtocol()
// rejects anything else (the historical 0 threw
// "IllegalArgumentException: Unsupported protocol", which the
// old code swallowed — mDNS never advertised on this phone).
nsdManager.registerService(info, NsdManager.PROTOCOL_DNS_SD, listener)
registrationListener = listener
} catch (e: Exception) {
android.util.Log.e(TAG, "mDNS registration failed", e)
onStatus("mDNS unavailable (${e.message}) — reach this receiver with --peer $localIp:$port")
}
}