mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(agent): the agent's tools reach the running app's package and live adb port (#2571)
This commit is contained in:
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) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.droiddeck.launcher.agent
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class AgentBashrcTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun aPinnedAdbPortGivesWayToTheLiveOne() {
|
||||
val bashrc = tmp.newFile(".bashrc")
|
||||
bashrc.writeText("alias ll='ls -l'\n# droiddeck-agent-path\nexport PATH=\"\$HOME/.local/bin:\$PATH\" ADB_SERIAL=127.0.0.1:5555 BROWSER=\"\$HOME/.local/bin/android-open\"\n")
|
||||
AgentSetup.unpinAdbSerial(bashrc)
|
||||
assertEquals(
|
||||
"alias ll='ls -l'\n# droiddeck-agent-path\nexport PATH=\"\$HOME/.local/bin:\$PATH\" ADB_SERIAL=\"\${ADB_SERIAL:-127.0.0.1:5555}\" BROWSER=\"\$HOME/.local/bin/android-open\"\n",
|
||||
bashrc.readText(),
|
||||
)
|
||||
AgentSetup.unpinAdbSerial(bashrc)
|
||||
assertEquals(1, Regex("ADB_SERIAL=").findAll(bashrc.readText()).count())
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -16,8 +16,10 @@ command -v claude >/dev/null || [ -x "$HOME/.local/bin/claude" ] ||
|
||||
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
for tool in dd-agent dd-lab-build dd-gh-login android-open; do install -m755 "$here/$tool" "$HOME/.local/bin/$tool"; done
|
||||
# DroidDeck passes the live loopback adb port; a fixed one here would go stale whenever wireless debugging is toggled.
|
||||
sed -i 's|ADB_SERIAL=127.0.0.1:5555 |ADB_SERIAL="${ADB_SERIAL:-127.0.0.1:5555}" |' "$HOME/.bashrc" 2>/dev/null || true
|
||||
grep -q 'droiddeck-agent-path' "$HOME/.bashrc" 2>/dev/null ||
|
||||
printf '\n# droiddeck-agent-path\nexport PATH="$HOME/.local/bin:$PATH" ADB_SERIAL=127.0.0.1:5555 BROWSER="$HOME/.local/bin/android-open"\n' >> "$HOME/.bashrc"
|
||||
printf '\n# droiddeck-agent-path\nexport PATH="$HOME/.local/bin:$PATH" ADB_SERIAL="${ADB_SERIAL:-127.0.0.1:5555}" BROWSER="$HOME/.local/bin/android-open"\n' >> "$HOME/.bashrc"
|
||||
|
||||
# Google publishes aapt2 for x86-64 Linux only; it runs here under qemu-user with Ubuntu's x86-64 runtime.
|
||||
x86=$HOME/x86root
|
||||
|
||||
Reference in new issue
Block a user