android auto: the car can see the app, and the root it opens is empty
Android Auto reaches a media app through `MediaBrowserService`, so `MediaService` becomes a `MediaLibraryService`, one intent filter carries three actions — media3's `MediaLibraryService` and `MediaSessionService`, plus the legacy `android.media.browse.MediaBrowserService` that Auto actually binds — and `res/xml/automotive_app_desc.xml` with the `com.google.android.gms.car.application` meta-data declares the app to the car. Auto lists SoulStream, opens it, and gets a browsable root. There is nothing under it: `onGetChildren` is left un-overridden so the default answers `ERROR_NOT_SUPPORTED` at once, and round fifty fills the tree. `onGetLibraryRoot` answers out of `Futures.immediateFuture` — no database, no I/O, nothing deferred — because `MediaLibraryServiceLegacyStub.onGetRoot` blocks the binder thread serving the host on that future with NO timeout and runs the callback on the main handler. A root that waits on anything is a head unit that gives up. The round carries a mitigation it cannot be split from. androidx/media #3158 — open since 2026-04-03, confirmed again 2026-09-04, reproduced on media3 1.11.0 — has a host that binds a `MediaLibraryService` with nothing playing drive the service round `onCreate` → `onBind` → `onGetSession` → `onConnect` → `onDestroy` at about thirty cycles a second, deterministically after a force-stop with no existing binding. That is exactly how Auto connects and exactly what the prober does. media3 will not act before an Auto-side fix lands, so the loop cannot be stopped from here; it can only be made to cost nothing. The session, the player, the notification provider, the audio-focus request and the becoming-noisy receiver move into `MediaHub` for the life of the PROCESS and `onCreate` allocates and registers nothing — round forty-eight's version would have built a platform session and a legacy browser stub thirty times a second, registered and unregistered a receiver sixty times a second, and abandoned audio focus thirty times a second while music was playing. Three consequences, each a trap for the next round. `onDestroy` calls `removeSession` and never `release()`: `removeSession` drops the session from that instance's map and clears its listener, which is what stops a destroyed service being called back, while `markReleased()` would latch `released` and leave a process-lifetime player that never updates the card again. The session is built with `MediaLibrarySession.Builder(applicationContext, …)` rather than the `(MediaLibraryService, …)` overload, because `MediaSessionServiceLegacyStub.initialize()` does `attachToBaseContext(sessionImpl.getContext())` — a session built against the Service pins a destroyed Service as the base context of a live `MediaBrowserServiceCompat`. And nothing releases the session any more, so it and its platform `MediaSessionCompat` live until the process dies; the walk's `one-session` check is what keeps that honest. `onCreate` logs `auto service created n=…` and `onDestroy` logs `auto service destroyed`, which are the only way to count the loop on a real phone. And the instrument. `tools/auto-prober/` is a throwaway app that binds the same way Auto does, with Auto's own root hints, walks whatever tree comes back, and logs one JSON object per event under `SoulAutoProbe`. It is framework-only (`android.media.browse.MediaBrowser`, not androidx, not media3) because that is the path Auto itself takes into a media3 app, and a prober built out of the library it is probing would not prove that path works. It lives outside `src-tauri/gen/android/` because `tauri android init` would delete it, and borrows the generated project's Gradle wrapper rather than shipping one, so a run downloads nothing. With SoulStream force-stopped there is no WebView, so no CDP, so `smoke.mjs` is blind to every bit of this — the prober is the only eye the project has on Auto without a head unit. The number it exists for is `root`: milliseconds from `connect()` to `onConnected()` with the process cold. Two corrections to the plan, argued in the files. `adb shell pm dump` is `dumpsys package` and prints NO application meta-data, so the Auto declaration cannot be a hard walk assertion — the two that ARE hard are the intent filters (`auto-browse`, `auto-library`), which catch the `TAURI_ANDROID_PROJECT_PATH` trap completely because the filters and the meta-data live in one library manifest and are lost together; the declaration is read instead by the prober, through `PackageManager.GET_META_DATA` and the app's own `Resources`, and echoed back by the walk as the advisory `auto-desc`. And the prober module compiles at jvmTarget 1.8 like every other module here, not 17 — JDK 17 is what RUNS Gradle. No Rust, no frontend, no cargo. The round was authored where none of it could be compiled and it has now been built and run: the Kotlin compiles, the APK installs, and the prober binds the app cold. `desc` resolves the meta-data to a real `xml/automotive_app_desc`; `filter` shows BOTH the legacy `android.media.browse.MediaBrowserService` and media3's own resolving to `MediaService`; `root` comes back at ~2.2 s with `ss:root` and a session token, of which the callback itself is about nine milliseconds and the rest is the cold process starting; `children` answers `n=-1` with nothing in it, which is the un-overridden default doing its job; and `auto service created n=1 reused=false` — #3158 does not loop here. One fix the first run earned. The prober read the descriptor's `name` out of the android namespace, but Google's `<uses name="media"/>` is a BARE attribute with no namespace, so it came back `[""]` — a real declaration and a dangling resource id reported identically, which is the single thing the event exists to tell apart. It reads the null namespace now and keeps ANDROID_NS as a fallback; the second run says `uses:["media"]`. None of this proves the car screen: the Desktop Head Unit or a real head unit is the only thing that shows what Auto draws, how it groups a tree, or whether a tap plays. This proves the app answers.
This commit is contained in:
1 parent
3a8ccd4640
commit
e1bf456743
16 files changed
+1412
-226
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- WITHOUT THIS THE PROBER MEASURES NOTHING AND LOOKS LIKE IT DID.
|
||||
targetSdk 30+ hides every other package from this one, so
|
||||
queryIntentServices() comes back empty and MediaBrowser.connect()
|
||||
fails with nothing useful in the log — which is indistinguishable
|
||||
from "SoulStream has no browse service", i.e. a false report about
|
||||
the one thing this app exists to measure. media3's own
|
||||
SessionToken.java carries the note "We ask the app to declare the
|
||||
<queries> tags, so it's expected that they are missing".
|
||||
Both forms: the package by name for the bind, the action for the
|
||||
PackageManager questions in ProbeActivity.filters(). -->
|
||||
<queries>
|
||||
<package android:name="com.soulstream.app" />
|
||||
<intent>
|
||||
<action android:name="android.media.browse.MediaBrowserService" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:label="SoulStream Auto prober">
|
||||
<!-- No launcher filter and no UI: it is started by name
|
||||
(`am start -n com.soulstream.autoprober/.ProbeActivity`), which
|
||||
is why it must be exported. noHistory and excludeFromRecents
|
||||
keep it out of the recents list Kyle actually uses. -->
|
||||
<activity
|
||||
android:name=".ProbeActivity"
|
||||
android:exported="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,292 @@
|
||||
package com.soulstream.autoprober
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.media.browse.MediaBrowser
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
|
||||
/**
|
||||
* The only eye this project has on Android Auto without a car.
|
||||
*
|
||||
* Auto talks to a media app through `MediaBrowserService`. With SoulStream
|
||||
* force-stopped there is no Activity, no WebView and therefore no DevTools
|
||||
* socket, so `tests/mobile/smoke.mjs` — which drives the app over CDP — is
|
||||
* blind to every bit of it. This app binds the same way Auto does, with
|
||||
* Auto's own root hints, walks whatever tree comes back, and prints one JSON
|
||||
* object per event under a single logcat tag, so the whole thing can be read
|
||||
* with `adb logcat -d -s SoulAutoProbe:I`.
|
||||
*
|
||||
* Framework classes only — `android.media.browse.MediaBrowser`, not
|
||||
* androidx, not media3. That is deliberate: it is the path Android Auto
|
||||
* itself takes into a media3 app (media3 serves the legacy
|
||||
* `android.media.browse.MediaBrowserService` action through
|
||||
* `MediaSessionService.onBind`), and a prober built out of the same library
|
||||
* as the thing it is probing would not prove that path works.
|
||||
*
|
||||
* It changes nothing on the phone. No permissions, no network, no storage,
|
||||
* no playback command. It force-stops nothing itself; `probe.sh` does that,
|
||||
* to SoulStream only, exactly as the phone walk already does. Every exit
|
||||
* path disconnects, and `onDestroy` disconnects again, so no binding is left
|
||||
* hanging on Kyle's phone if a step throws.
|
||||
*
|
||||
* Run it through `tools/auto-prober/probe.sh`, which builds, installs,
|
||||
* clears logcat, force-stops SoulStream and starts this with the right
|
||||
* extras.
|
||||
*/
|
||||
class ProbeActivity : Activity() {
|
||||
companion object {
|
||||
private const val TAG = "SoulAutoProbe"
|
||||
private const val PKG = "com.soulstream.app"
|
||||
private const val SVC = "com.soulstream.mediasession.MediaService"
|
||||
private const val BROWSE = "android.media.browse.MediaBrowserService"
|
||||
private const val LIBRARY = "androidx.media3.session.MediaLibraryService"
|
||||
private const val ANDROID_NS = "http://schemas.android.com/apk/res/android"
|
||||
|
||||
/** Longer than Auto's own patience and shorter than a person's. A
|
||||
* root that has not come back by now is the failure this whole app
|
||||
* exists to catch. */
|
||||
private const val WATCHDOG_MS = 8000L
|
||||
}
|
||||
|
||||
private val main = Handler(Looper.getMainLooper())
|
||||
private var browser: MediaBrowser? = null
|
||||
private var t0 = 0L
|
||||
private var depth = 2
|
||||
/** subscriptions asked for and not yet answered; zero means the walk is
|
||||
* over. Main thread only — every callback lands there. */
|
||||
private var pending = 0
|
||||
private var nodes = 0
|
||||
private var leaves = 0
|
||||
private var finished = false
|
||||
private val subscribed = HashSet<String>()
|
||||
private val watchdog = Runnable { fail("watchdog after " + WATCHDOG_MS + "ms") }
|
||||
|
||||
private fun ms() = System.currentTimeMillis() - t0
|
||||
private fun say(o: JSONObject) { Log.i(TAG, o.toString()) }
|
||||
|
||||
override fun onCreate(saved: Bundle?) {
|
||||
super.onCreate(saved)
|
||||
t0 = System.currentTimeMillis()
|
||||
depth = intent?.getIntExtra("depth", 2) ?: 2
|
||||
val recent = intent?.getBooleanExtra("recent", false) ?: false
|
||||
|
||||
say(
|
||||
JSONObject().put("ev", "start").put("pkg", PKG).put("svc", SVC)
|
||||
.put("depth", depth).put("recent", recent),
|
||||
)
|
||||
describe()
|
||||
filters()
|
||||
|
||||
/* Auto's own root hints, spelled the way the framework spells them.
|
||||
media3's LegacyConversions.convertToLibraryParams reads exactly
|
||||
these four and turns them into the LibraryParams that
|
||||
LibraryTree.onGetLibraryRoot logs on the far side — so what goes in
|
||||
here and what comes out of `adb logcat -s SoulStream:I` are two
|
||||
ends of one wire. */
|
||||
val hints = Bundle()
|
||||
hints.putBoolean("android.service.media.extra.RECENT", recent)
|
||||
hints.putInt("androidx.media.MediaBrowserCompat.Extras.KEY_ROOT_CHILDREN_LIMIT", 4)
|
||||
hints.putInt(
|
||||
"androidx.media.MediaBrowserCompat.Extras.KEY_ROOT_CHILDREN_SUPPORTED_FLAGS",
|
||||
MediaBrowser.MediaItem.FLAG_BROWSABLE or MediaBrowser.MediaItem.FLAG_PLAYABLE,
|
||||
)
|
||||
hints.putInt("android.media.extras.MEDIA_ART_SIZE_HINT_PIXELS", 320)
|
||||
|
||||
main.postDelayed(watchdog, WATCHDOG_MS)
|
||||
try {
|
||||
val b = MediaBrowser(this, ComponentName(PKG, SVC), connection, hints)
|
||||
browser = b
|
||||
b.connect()
|
||||
} catch (e: Exception) {
|
||||
fail("connect threw: " + e)
|
||||
}
|
||||
}
|
||||
|
||||
private val connection = object : MediaBrowser.ConnectionCallback() {
|
||||
/** The number the whole exercise is for: milliseconds from
|
||||
* `connect()` to here, with the app's process cold. Auto gives a
|
||||
* media app a few seconds and then drops it. */
|
||||
override fun onConnected() {
|
||||
val b = browser ?: return
|
||||
val root = try { b.root } catch (e: Exception) { "" }
|
||||
val token = try { b.sessionToken != null } catch (e: Exception) { false }
|
||||
say(
|
||||
JSONObject().put("ev", "root").put("ms", ms())
|
||||
.put("id", root).put("tokenOk", token),
|
||||
)
|
||||
if (root.isEmpty()) { fail("no root id"); return }
|
||||
walk(root, 0)
|
||||
}
|
||||
|
||||
/* the two ways a bind ends badly. "connection failed" with nothing
|
||||
else in the log is usually package visibility — see <queries> in
|
||||
the manifest — or a service that answered null from onGetSession. */
|
||||
override fun onConnectionFailed() { fail("connection failed") }
|
||||
override fun onConnectionSuspended() { fail("connection suspended") }
|
||||
}
|
||||
|
||||
/** Breadth-ish, depth-limited, and every node subscribed at most once.
|
||||
* A `MediaBrowserService` may answer a subscription more than once
|
||||
* (that is how it pushes a changed folder), so both callbacks latch. */
|
||||
private fun walk(parent: String, level: Int) {
|
||||
val b = browser ?: return
|
||||
if (parent.isEmpty() || level > depth) { maybeDone(); return }
|
||||
if (!subscribed.add(parent)) { maybeDone(); return }
|
||||
pending += 1
|
||||
b.subscribe(
|
||||
parent,
|
||||
object : MediaBrowser.SubscriptionCallback() {
|
||||
private var answered = false
|
||||
|
||||
override fun onChildrenLoaded(
|
||||
parentId: String,
|
||||
children: MutableList<MediaBrowser.MediaItem>,
|
||||
) {
|
||||
if (answered) return
|
||||
answered = true
|
||||
val arr = JSONArray()
|
||||
for (c in children) {
|
||||
arr.put(
|
||||
JSONObject()
|
||||
.put("id", c.mediaId ?: "")
|
||||
.put("title", (c.description.title ?: "").toString())
|
||||
.put("browsable", c.isBrowsable)
|
||||
.put("playable", c.isPlayable),
|
||||
)
|
||||
}
|
||||
say(
|
||||
JSONObject().put("ev", "children").put("parent", parentId)
|
||||
.put("n", children.size).put("items", arr),
|
||||
)
|
||||
nodes += 1
|
||||
/* descend BEFORE this one is retired, so `pending` never
|
||||
touches zero while there is more tree to read */
|
||||
for (c in children) {
|
||||
if (c.isBrowsable) walk(c.mediaId ?: "", level + 1) else leaves += 1
|
||||
}
|
||||
pending -= 1
|
||||
maybeDone()
|
||||
}
|
||||
|
||||
override fun onError(parentId: String) {
|
||||
if (answered) return
|
||||
answered = true
|
||||
say(
|
||||
JSONObject().put("ev", "children").put("parent", parentId)
|
||||
.put("n", -1).put("items", JSONArray()),
|
||||
)
|
||||
pending -= 1
|
||||
maybeDone()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/** The app's Auto declaration, read out of the app's OWN resources.
|
||||
* This is the half `adb shell pm dump` cannot do: `dumpsys package`
|
||||
* prints resolver tables and package state and no `<meta-data>` at all,
|
||||
* so the only way to prove `com.google.android.gms.car.application`
|
||||
* points at a real resource — rather than at a dangling id — is to
|
||||
* resolve the int and then open it. */
|
||||
private fun describe() {
|
||||
val o = JSONObject().put("ev", "desc")
|
||||
try {
|
||||
val ai = packageManager.getApplicationInfo(PKG, PackageManager.GET_META_DATA)
|
||||
val id = ai.metaData?.getInt("com.google.android.gms.car.application", 0) ?: 0
|
||||
o.put("metaResId", id)
|
||||
if (id != 0) {
|
||||
val res = packageManager.getResourcesForApplication(ai)
|
||||
o.put("resName", res.getResourceName(id))
|
||||
val uses = JSONArray()
|
||||
val xml = res.getXml(id)
|
||||
var ev = xml.eventType
|
||||
while (ev != XmlPullParser.END_DOCUMENT) {
|
||||
if (ev == XmlPullParser.START_TAG && xml.name == "uses") {
|
||||
// `name` here carries NO namespace. Google's own
|
||||
// descriptor is `<uses name="media"/>` — a bare
|
||||
// attribute, not `android:name` — so reading it out of
|
||||
// ANDROID_NS returns null and the probe reports [""],
|
||||
// which is indistinguishable from a descriptor that
|
||||
// declares nothing. That is the one thing this event
|
||||
// exists to tell apart from a dangling resource id, so
|
||||
// the null namespace is the real read and ANDROID_NS is
|
||||
// only a fallback for a descriptor written the other way.
|
||||
uses.put(
|
||||
xml.getAttributeValue(null, "name")
|
||||
?: xml.getAttributeValue(ANDROID_NS, "name")
|
||||
?: ""
|
||||
)
|
||||
}
|
||||
ev = xml.next()
|
||||
}
|
||||
xml.close()
|
||||
o.put("uses", uses)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
o.put("err", e.toString())
|
||||
}
|
||||
say(o)
|
||||
}
|
||||
|
||||
/** What the PackageManager thinks each of the two actions resolves to,
|
||||
* scoped to SoulStream. An empty list for `browse` and a present one
|
||||
* for `media3` is a manifest that landed half; two empty lists with a
|
||||
* working app is package visibility eating this prober. */
|
||||
private fun filters() {
|
||||
val o = JSONObject().put("ev", "filter")
|
||||
for (pair in listOf(Pair("browse", BROWSE), Pair("media3", LIBRARY))) {
|
||||
val arr = JSONArray()
|
||||
try {
|
||||
for (ri in packageManager.queryIntentServices(Intent(pair.second).setPackage(PKG), 0)) {
|
||||
arr.put(ri.serviceInfo.packageName + "/" + ri.serviceInfo.name)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
arr.put("ERR " + e)
|
||||
}
|
||||
o.put(pair.first, arr)
|
||||
}
|
||||
say(o)
|
||||
}
|
||||
|
||||
private fun maybeDone() {
|
||||
if (finished || pending > 0) return
|
||||
say(
|
||||
JSONObject().put("ev", "done").put("ms", ms())
|
||||
.put("nodes", nodes).put("leaves", leaves),
|
||||
)
|
||||
stop()
|
||||
}
|
||||
|
||||
private fun fail(why: String) {
|
||||
if (finished) return
|
||||
say(JSONObject().put("ev", "fail").put("why", why).put("ms", ms()))
|
||||
stop()
|
||||
}
|
||||
|
||||
/** One way out, and `onDestroy` repeats it. A prober that left a binding
|
||||
* behind would hold SoulStream's service up for as long as this process
|
||||
* lived, which is the opposite of what it is for. */
|
||||
private fun stop() {
|
||||
if (finished) return
|
||||
finished = true
|
||||
main.removeCallbacks(watchdog)
|
||||
try { browser?.disconnect() } catch (_: Exception) {}
|
||||
browser = null
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
main.removeCallbacks(watchdog)
|
||||
try { browser?.disconnect() } catch (_: Exception) {}
|
||||
browser = null
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user