Modern Apps git

← Modern-Apps.git

maauto: send field-5-only ServiceDiscoveryRequest

Commit
508802a742317c61cdfc4bc5d5e6c212f64dba1d
Author
vayun-mathur <[email protected]>
When
2026-09-12 04:46 UTC (2 months ago)
Parents
a0a91fd

Diff

auto/docs/HANDOFF.md
diff --git a/auto/docs/HANDOFF.md b/auto/docs/HANDOFF.mdindex b86d8d43c6..83db5a46a9 100644--- a/auto/docs/HANDOFF.md+++ b/auto/docs/HANDOFF.md@@ -80,17 +80,32 @@ it is short and not obfuscated beyond names. What it does: | 5 | `xoa.g` string | **always** | | 6 | `xoa.h` message `xgs` | only if version high enough and `izu.j != null` | -Field 5 is `Build.MODEL`, with `" " + Build.MANUFACTURER` appended when MODEL does not-already start with MANUFACTURER — e.g. `"Pixel 8 Google"`. It is the **only unconditional-field**.--It is then sent with `((jbj) obj).k(5, …)`, and `k()` routes to `o(i, msg, true, …)` — the-`true` is what sets the CONTROL flag. So **gearhead does set `0x04` on this message**, even-though DHU never sets it on anything it sends.--**Next thing to try:** send *only* field 5, containing `"$MODEL $MANUFACTURER"` exactly as-gearhead composes it, with the CONTROL flag set. The current code sends field 4 = `MODEL`-and field 5 = `MANUFACTURER` with the flag clear, which matches gearhead on neither count.+Field 5 is composed from `Build.MANUFACTURER` and `Build.MODEL`: unless MODEL+already starts with MANUFACTURER, gearhead sends `MANUFACTURER + " " + MODEL`+(e.g. `"Google Pixel 8"` — manufacturer first, not `"Pixel 8 Google"`). This is+verified Dalvik ground truth: `disasm_jog.txt` shows `bJ(MODEL, MANUFACTURER,+" ")` and `a.bJ` returns `str2 + str3 + str`, i.e. MANUFACTURER + " " + MODEL;+hasbit 16 = field 5 confirmed. It is the **only unconditional field** — `g/h/i`+come from optional head-unit resource config, `f` from an optional string+resource, `j` from a version-gated cert string, and `jog` nulls `g/h/i/f` after+the first send, so every repeat is field-5-only by construction.++It is then sent with `((jbj) obj).k(5, …)`, and `k()` routes to `o(i, msg, true,+…)` — but `m()` there constructs `new izn(z, false, …)`, and `izn.a` is+**isEncrypted**, `izn.b` is **isMediaPayload** (see `izn.toString()`:+"isEncrypted;isMediaPayload;callbackId;maxUnackedDuration", confirmed against+the disassembled `Lizm;-><init>` and the `Ljbe` flag assembly where+`Lizm->h`(encrypted)→`0x08` and `Lizm->f`(isControl/canFragment)→`0x04`).+So the `true` sets the **ENCRYPTED** bit, not CONTROL: gearhead's message-5+frame is FIRST|LAST|ENCRYPTED = `0x0B` with the CONTROL bit **clear** — same as+every other control-channel frame both sides send. The earlier "CONTROL on/off"+experiments were testing a bit neither side ever sets on channel 0; no further+flag experiments are needed.++**Fix applied (Task 3):** send *only* field 5 containing `"Google Pixel 8"`+(composed by `composeDiscoveryLabel()` in `GalControlSession.kt`), framing+unchanged at `0x0B`. The old code sent field 4 = `MODEL` + field 5 =+`MANUFACTURER`, which matches gearhead on neither count.  If that still fails, capture the decrypted bytes gearhead itself sends: install real Android Auto on a phone, point DHU at it through `dhu_relay.py`, and compare. The relay only sees
auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt
diff --git a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.ktindex 8ba00183ac..463d0872e2 100644--- a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt+++ b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt@@ -39,8 +39,8 @@ fun isChannelControlMessage(type: Int): Boolean = when (type) { class GalConnection(     private val transport: GalTransport,     sslContext: SSLContext,-    deviceName: String,-    deviceBrand: String = deviceName,+    deviceModel: String,+    deviceManufacturer: String = deviceModel,     private val onChannelMessage: ChannelMessageHandler = ChannelMessageHandler { },     /**      * Traces every message and state change. A live session is otherwise opaque, and this
auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt
diff --git a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.ktindex 111d2e06e8..f0e07af04c 100644--- a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt+++ b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt@@ -54,8 +54,10 @@ enum class SessionState {  */ class GalControlSession(     private val engine: SSLEngine,-    private val deviceName: String,-    private val deviceBrand: String = deviceName,+    /** Android `Build.MODEL`, e.g. "Pixel 8". */+    private val deviceModel: String,+    /** Android `Build.MANUFACTURER`, e.g. "Google". Defaults for host tests. */+    private val deviceManufacturer: String = deviceModel,     private val supportedVersion: GalVersion = VersionNegotiation.SUPPORTED, ) {     var state: SessionState = SessionState.AWAITING_VERSION@@ -170,11 +172,20 @@ class GalControlSession(         return listOf(             OutboundMessage(                 type = GalMessage.Control.SERVICE_DISCOVERY_REQUEST,-                // Both name and brand: a head unit rejects the request outright when only-                // one is set, which shows up as a bare MessageError with no explanation.+                // Field 5 ONLY, composed exactly as gearhead does it in `jog.run()`:+                // `Build.MODEL`, with `"$MANUFACTURER "` prepended unless MODEL+                // already starts with MANUFACTURER (e.g. "Google Pixel 8").+                // Field 5 (`xoa.g`, hasbit 16) is the only unconditional field;+                // fields 1-3 (`izu.g/h/i`), 4 (`izu.f`) and 6 (`izu.j`) are sent+                // only when that state is non-null, which it is not on the DHU+                // path -- and `jog` nulls them after the first send, so repeats+                // are field-5-only by construction. A DHU answers anything else+                // here with a bare MessageError (0xff). Framing is unchanged:+                // `jbj.k(5)` routes to `o(..., true, ...)` where the `true` is+                // isEncrypted (izn.a -> 0x08), NOT the CONTROL bit, which stays+                // clear on this message -- flags FIRST|LAST|ENCRYPTED = 0x0B.                 payload = ServiceDiscoveryRequest.newBuilder()-                    .setDeviceName(deviceName)-                    .setDeviceBrand(deviceBrand)+                    .setDeviceBrand(composeDiscoveryLabel(deviceModel, deviceManufacturer))                     .build()                     .toByteArray(),                 encrypted = true,@@ -279,3 +290,13 @@ class GalControlSession(         return emptyList()     } }++/**+ * Composes the `ServiceDiscoveryRequest` device label exactly as gearhead does.+ *+ * `jog.run()` reads `Build.MANUFACTURER` and `Build.MODEL` and, unless MODEL+ * already starts with MANUFACTURER, concatenates `MANUFACTURER + " " + MODEL`+ * (`a.bJ(model, manufacturer, " ")` returns `str2 + str3 + str`).+ */+internal fun composeDiscoveryLabel(model: String, manufacturer: String): String =+    if (model.startsWith(manufacturer)) model else "$manufacturer $model"
auto/protocol/src/main/proto/gal/control.proto
diff --git a/auto/protocol/src/main/proto/gal/control.proto b/auto/protocol/src/main/proto/gal/control.protoindex d0b56a7979..f4e8c0239f 100644--- a/auto/protocol/src/main/proto/gal/control.proto+++ b/auto/protocol/src/main/proto/gal/control.proto@@ -95,8 +95,18 @@ enum NavigationFocusType {  // Control message 5. Sent by the PHONE. Only sent once version negotiation reaches >= 1.6. //-// Fields 4 and 5 are optional in this build's descriptor but aasdk has both as required, and-// a Desktop Head Unit answers MessageError when only one is set, so both are always populated.+// ONLY field 5 goes on the wire in practice: gearhead's `jog.run()` sets fields+// 1-3 (`izu.g/h/i`), 4 (`izu.f`) and 6 (`izu.j`) only when that state is non-null,+// and all of it is null on the plain DHU path (fields 1-3/4 come from optional+// head-unit resource config, 6 needs a version-gated non-null string). `jog` then+// nulls g/h/i/f, so every repeat is field-5-only by construction. Field 5 is the+// device label: `Build.MODEL` with `"$MANUFACTURER "` prepended unless MODEL+// already starts with MANUFACTURER (e.g. "Google Pixel 8").+//+// A Desktop Head Unit answers any other shape here with a bare MessageError+// (0xff), which is what blocked us until this matched gearhead byte for byte.+// The fields stay `optional` here (proto2 required-ness is load-bearing in the+// other direction only), and the sender sets exactly field 5. message ServiceDiscoveryRequest {   optional bytes field1 = 1;   optional bytes field2 = 2;
auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt
diff --git a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.ktindex adce86545b..1cba60cd37 100644--- a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt+++ b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt@@ -48,7 +48,7 @@ class GalConnectionTest {     }      private fun connection(transport: FakeTransport) =-        GalConnection(transport, TestTls.context(), deviceName = "Pixel 8")+        GalConnection(transport, TestTls.context(), deviceModel = "Pixel 8")      /** A control frame exactly as the Desktop Head Unit puts it on the wire. */     private fun headUnitFrame(type: Int, payload: ByteArray): ByteArray =@@ -139,7 +139,7 @@ class GalConnectionTest {         val connection = GalConnection(             transport,             TestTls.context(),-            deviceName = "Pixel 8",+            deviceModel = "Pixel 8",             // Named: `trace` is also a trailing lambda, so positional binding here would             // silently attach this to the wrong parameter.             onChannelMessage = { received += it },
auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt
diff --git a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.ktindex 608875a922..48348db212 100644--- a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt+++ b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt@@ -15,6 +15,7 @@ import javax.net.ssl.SSLEngine import javax.net.ssl.SSLEngineResult.HandshakeStatus import javax.net.ssl.SSLEngineResult.Status import kotlin.test.Test+import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull@@ -38,7 +39,8 @@ class GalControlSessionTest {         rootPem = File(assetDir, "root.pem").readText(),     ) -    private fun session(engine: SSLEngine) = GalControlSession(engine, deviceName = "Pixel 8")+    private fun session(engine: SSLEngine) =+        GalControlSession(engine, deviceModel = "Pixel 8", deviceManufacturer = "Google")      @Test     fun `a full bring-up reaches ACTIVE with the head unit's services`() {@@ -78,10 +80,10 @@ class GalControlSessionTest {         ).single()         assertEquals(GalMessage.Control.SERVICE_DISCOVERY_REQUEST, discovery.type)         assertTrue(discovery.encrypted, "everything after auth is wrapped")-        assertEquals(-            "Pixel 8",-            ServiceDiscoveryRequest.parseFrom(discovery.payload).deviceName,-        )+        // Field 5 only, composed exactly as gearhead does: MANUFACTURER + " " + MODEL.+        val request = ServiceDiscoveryRequest.parseFrom(discovery.payload)+        assertEquals("Google Pixel 8", request.deviceBrand)+        assertEquals(false, request.hasDeviceName())         assertEquals(SessionState.DISCOVERING, session.state)          // 4. The head unit advertises; we consume.@@ -149,6 +151,30 @@ class GalControlSessionTest {         assertTrue(session.failure!!.contains("discovery floor"))     } +    @Test+    fun `the discovery label matches gearhead's composition`() {+        // `jog.run()`: MODEL with "$MANUFACTURER " prepended unless MODEL already+        // starts with MANUFACTURER. `a.bJ(model, manufacturer, " ")` returns+        // str2 + str3 + str, i.e. MANUFACTURER + " " + MODEL.+        assertEquals("Google Pixel 8", composeDiscoveryLabel("Pixel 8", "Google"))+        assertEquals("Google Pixel 8 Pro", composeDiscoveryLabel("Pixel 8 Pro", "Google"))+        assertEquals("GooglePixel", composeDiscoveryLabel("GooglePixel", "Google"))+    }++    @Test+    fun `the discovery request pins field 5 alone on the wire`() {+        // Field 5 = length-delimited string: tag 0x2A, then length, then bytes.+        // "Google Pixel 8" is 14 bytes, so the whole request is 16 bytes.+        val expected = byteArrayOf(0x2A, 0x0E) + "Google Pixel 8".toByteArray()+        assertContentEquals(+            expected,+            ServiceDiscoveryRequest.newBuilder()+                .setDeviceBrand(composeDiscoveryLabel("Pixel 8", "Google"))+                .build()+                .toByteArray(),+        )+    }+     @Test     fun `a ping is answered with the same timestamp`() {         val session = session(GalCredential.serverEngine(context()))
auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt b/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.ktindex f31df3c38b..81ad9176a5 100644--- a/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt+++ b/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt@@ -61,8 +61,8 @@ class ProjectionService : Service() {             val connection = GalConnection(                 transport = StreamTransport(socket.getInputStream(), socket.getOutputStream()),                 sslContext = GalCredential.fromAssets(assets),-                deviceName = Build.MODEL,-                deviceBrand = Build.MANUFACTURER,+                deviceModel = Build.MODEL,+                deviceManufacturer = Build.MANUFACTURER,                 onChannelMessage = { message -> video?.onMessage(message.type, message.payload) },                 trace = { Log.d(TAG, it) },             )