<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lyubomir Kuznetsov on Medium]]></title>
        <description><![CDATA[Stories by Lyubomir Kuznetsov on Medium]]></description>
        <link>https://medium.com/@lindevhard?source=rss-587d5647fac1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cuAlUYHKCwUmsehBg7tuWA.png</url>
            <title>Stories by Lyubomir Kuznetsov on Medium</title>
            <link>https://medium.com/@lindevhard?source=rss-587d5647fac1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:13:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lindevhard/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How ADB Wi-Fi pairing works: QR codes, mDNS, and two different ports]]></title>
            <link>https://medium.com/@lindevhard/how-adb-wi-fi-pairing-works-qr-codes-mdns-and-two-different-ports-ebe1feea0942?source=rss-587d5647fac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebe1feea0942</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[adb]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Lyubomir Kuznetsov]]></dc:creator>
            <pubDate>Sun, 25 Oct 2026 17:02:34 GMT</pubDate>
            <atom:updated>2026-10-25T17:02:34.153Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IlNIcH15kgppW7hjpgFdcg.png" /></figure><p>I ran into this while testing an app on a physical Pixel over Wi-Fi. Android Studio’s QR pairing worked, but in my setup getting the code meant opening a project and sometimes waiting for Gradle sync, even though I was doing the rest of the work outside the IDE.</p><p>adb pair was not quite equivalent. Android exposes a temporary endpoint for pairing, while the later ADB connection uses another dynamically selected port. After a reboot or network change, that connection endpoint may change again.</p><p>I wanted one command, one QR scan, and the phone ready in adb devices. That annoyance led me to build <a href="https://github.com/LinDevHard/wadb">wadb</a>, but the useful part was tracing what Android Studio puts in the QR code and how the phone becomes discoverable afterward.</p><h3>It is not one connection</h3><p>The flow has two services and two different jobs:</p><figure><img alt="adb wifi pairing flow" src="https://cdn-images-1.medium.com/max/1024/1*saBE4jiww2TK16YGv0gGLQ.png" /><figcaption>ADB wifi pairing flow</figcaption></figure><p>The ordering matters. _adb-tls-connect._tcp is normally advertised while Wireless debugging is active, so it may exist before pairing begins. Pairing authorizes the workstation; it does not create the regular ADB transport or guarantee that the host will receive a fresh mDNS event for it afterward.</p><h3>The QR carries a secret and an mDNS name</h3><p>The QR code shown by Android Studio contains a string shaped like this:</p><pre>WIFI:T:ADB;S:studio-AbCdEf1234;P:a1B2c3D4e5F6;;</pre><p>ADB reuses the Wi-Fi QR envelope with ADB-specific meanings:</p><ul><li>T:ADB identifies an ADB pairing payload.</li><li>S: requests an mDNS service instance name.</li><li>P: contains the temporary pairing secret.</li></ul><p>Android Studio conventionally uses studio-&lt;random-10&gt; for the service name, and wadb follows that convention. Android recognizes the payload from T:ADB; the studio- prefix itself is not required by the parser.</p><p>After scanning, Android starts a pairing server and publishes the requested name as an _adb-tls-pairing._tcp instance:</p><pre>studio-AbCdEf1234._adb-tls-pairing._tcp.local</pre><p>This turns the S: value into a correlation ID. If several phones expose pairing services on the same LAN, the host can wait for the exact random name from its QR instead of choosing the first announcement it sees.</p><p>In wadb, the service suffix and pairing secret come from crypto/rand. The random-byte mapping uses rejection sampling rather than byte modulo, avoiding modulo bias in the generated strings.</p><h3>Pairing is the trust step</h3><p>Once the matching endpoint is found, the host runs:</p><pre>adb pair &lt;host&gt;:&lt;pairing-port&gt;</pre><p>wadb sends the shared secret through standard input instead of placing it in the command arguments. The installed adb establishes TLS, authenticates the shared secret using SPAKE2, and exchanges the peer information needed for future connections, including the host public key and device GUID.</p><p>The pairing server is temporary. Normal ADB traffic uses the separately advertised _adb-tls-connect._tcp endpoint:</p><pre>adb connect &lt;host&gt;:&lt;connection-port&gt;</pre><p>This explains a confusing result: adb pair can succeed while the phone still does not appear in adb devices. Trust has been established, but the host has not found or connected to the regular TLS transport.</p><p>It also creates a small discovery race. Because the connect service may have been active before pairing, waiting only for a new mDNS “create” event after adb pair is not enough.</p><h3>The awkward part is discovery</h3><p>A development machine often has several interfaces: Wi-Fi, Ethernet, a VPN, or container bridges. Multicast can take the wrong path, and link-local IPv6 addresses are unusable unless they include an interface zone such as %en0. An access point can also block peer-to-peer multicast entirely.</p><p>There is a timing problem too. A live browse can miss a short-lived announcement or start after a service is already active. The adb server runs its own mDNS implementation and may have a different view of the same network.</p><p>The implementation therefore combines two observations:</p><p><strong>1. </strong>a direct DNS-SD browse for _adb-tls-connect._tcp;<br><strong>2. </strong>the current service snapshot reported by adb mdns services.</p><p>The results are merged and deduplicated by exact host:port. The second source is useful, but its human-readable output is not a stable machine contract and has changed between platform-tools versions. The parser treats it as a hint and skips rows it cannot understand.</p><p>When the pairing address is known, endpoints on that same host are tried first. The separate wadb connect command also accepts --device when explicit selection is needed on a network with several paired phones.</p><p>For multi-interface hosts, --iface binds the direct browse to one interface. The interface is validated first, so a typo or inactive interface fails immediately instead of looking like a long discovery timeout. With an explicit interface, a discovered link-local IPv6 address can be given the required zone; without one, an unscoped link-local address is skipped.</p><h3>Where the helper stops</h3><p>I stopped at orchestration: the tool generates an ephemeral service identifier and pairing secret, renders the QR code, and locates endpoints. Key exchange, TLS, host keys, and the ADB transport remain inside the installed adb. Reimplementing that layer would add security and compatibility risk without improving the workflow I was trying to fix.</p><p>Pairing trust can survive a reboot or Wi-Fi change even when the connection port changes. The connect service instance normally looks like:</p><pre>adb-&lt;device-serial&gt;-&lt;random-suffix&gt;</pre><p>When that convention exposes the serial, it can be used to associate the changing network endpoint with the same physical phone. Otherwise the address has to remain the fallback identity.</p><h3>Android 17 changes the reconnect story</h3><p>Android 17 and platform-tools 37 introduce ADB Wi-Fi 2.0. On a trusted wireless debugging network, a paired device can automatically reconnect to the workstation. That removes much of the need for a separate rediscovery command on new devices, although the QR pairing flow and the two-service architecture remain.</p><h3>What I verified</h3><p>The part I had originally missed was that a successful adb pair is only the trust step. A usable wireless device still depends on finding a separate _adb-tls-connect._tcp endpoint, often on another port.</p><p>I tested this workflow on macOS with a physical Pixel. The repository also has unit and command-path tests, but its real mDNS, pairing, and connection flow is not exercised in CI. Linux is supported and expected to work; Windows remains experimental and unverified. Automatic wireless discovery requires working mDNS, although direct adb pair and adb connect endpoints do not.</p><p>For platform scope, Wireless debugging requires Android 11/API 30 or newer on phones and Android 13/API 33 or newer on TV and Wear OS. Pairing authorizes the workstation’s host key, while actual ADB access remains conditional on Wireless debugging being enabled on an allowed network. The authorization persists until the workstation is forgotten or ADB authorizations are revoked.</p><h3>References</h3><ul><li><a href="https://android.googlesource.com/platform/packages/modules/adb/+/HEAD/docs/dev/adb_wifi.md">Architecture of ADB Wi-Fi</a></li><li><a href="https://android.googlesource.com/platform/packages/apps/Settings/+/refs/heads/main/src/com/android/settings/wifi/dpp/AdbQrCode.java">Android’s ADB QR parser</a></li><li><a href="https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/pairing_connection/include/adb/pairing/pairing_connection.h">ADB pairing connection API</a></li><li><a href="https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/pairing_connection/pairing_connection.cpp">ADB pairing and SPAKE2 implementation</a></li><li><a href="https://developer.android.com/tools/adb#connect-to-a-device-over-wi-fi">Android Debug Bridge documentation</a></li><li><a href="https://github.com/LinDevHard/wadb">wadb source code</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebe1feea0942" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>