fix(agent): the agent's tools reach the running app's package and live adb port (#2571)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-13 13:15:55 -05:00
1 parent 13b05656aa
commit 8a37e71e10
4 files changed
+34 -2

No files matched your search

@@ -382,7 +382,7 @@ object AgentHost {
val adb = AgentAdb.prepare(app)
val env = listOf(
"/usr/bin/env", "HOME=/root", "PATH=$GUEST_PATH", "LANG=C.UTF-8",
"ADB_SERIAL=${adb.serial}", "ADB_VENDOR_KEYS=${adb.vendorKeys}",
"ADB_SERIAL=${adb.serial}", "ADB_VENDOR_KEYS=${adb.vendorKeys}", "DROIDDECK_PACKAGE=${app.packageName}",
"DD_AGENT=1", "DD_AGENT_INBOX=${File(app.filesDir, "agent").path}", "BROWSER=/root/.local/bin/android-open", "DD_BROWSER_DISPLAY=${AgentAdb.browserDisplay}",
)
val shell = listOf(
@@ -191,6 +191,14 @@ object AgentSetup {
for (name in HELPERS) copyAsset(app, "agent/$name", File(bin, name))
val ctl = File(root, CTL.removePrefix("/")).apply { mkdirs() }
for (name in app.assets.list("agent/ctl").orEmpty()) copyAsset(app, "agent/ctl/$name", File(ctl, name))
unpinAdbSerial(File(root, "root/.bashrc"))
}
/** Older tools/agent/setup pinned the adb port in .bashrc, which overrides the live port DroidDeck passes. */
internal fun unpinAdbSerial(bashrc: File) {
val text = runCatching { bashrc.readText() }.getOrNull() ?: return
val fixed = text.replace("ADB_SERIAL=127.0.0.1:5555 ", "ADB_SERIAL=\"\${ADB_SERIAL:-127.0.0.1:5555}\" ")
if (fixed != text) runCatching { bashrc.writeText(fixed) }
}
private fun copyAsset(app: Context, asset: String, target: File) {