mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(agent): run the setup package install as fake root (#2539)
This commit is contained in:
1 parent
d058bab64f
commit
33dbd8755f
7 files changed
+110
-9
No files matched your search
@@ -52,6 +52,7 @@ object AgentHost {
|
||||
|
||||
private const val TAG = "AgentHost"
|
||||
private const val WORKSPACE = "/root/DroidDeck"
|
||||
internal const val GUEST_PATH = "/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
private const val TICK_MS = 1_000L
|
||||
private const val IDLE_TICK_MS = 5_000L
|
||||
|
||||
@@ -377,10 +378,10 @@ object AgentHost {
|
||||
* proot over the installed rootfs, without a session. Loopback adb is connected first so
|
||||
* droiddeckctl reaches the app.
|
||||
*/
|
||||
fun guest(app: Context, command: List<String>, workdir: String = "/root", connectAdb: Boolean = true): ProcessBuilder {
|
||||
fun guest(app: Context, command: List<String>, workdir: String = "/root", connectAdb: Boolean = true, fakeRoot: Boolean = false): ProcessBuilder {
|
||||
val adb = AgentAdb.prepare(app)
|
||||
val env = listOf(
|
||||
"/usr/bin/env", "HOME=/root", "PATH=/root/.local/bin:/usr/local/bin:/usr/bin:/bin", "LANG=C.UTF-8",
|
||||
"/usr/bin/env", "HOME=/root", "PATH=$GUEST_PATH", "LANG=C.UTF-8",
|
||||
"ADB_SERIAL=${adb.serial}", "ADB_VENDOR_KEYS=${adb.vendorKeys}",
|
||||
"DD_AGENT=1", "DD_AGENT_INBOX=${File(app.filesDir, "agent").path}", "BROWSER=/root/.local/bin/android-open", "DD_BROWSER_DISPLAY=${AgentAdb.browserDisplay}",
|
||||
)
|
||||
@@ -390,7 +391,7 @@ object AgentHost {
|
||||
(if (connectAdb) "adb start-server >/dev/null 2>&1; adb connect \"\$ADB_SERIAL\" >/dev/null 2>&1; " else "") +
|
||||
"cd \"$1\" 2>/dev/null; shift; exec \"$@\"", "sh", workdir,
|
||||
)
|
||||
val proot = LinuxRuntime.command(app, null, null, Environment.getExternalStorageDirectory(), env + shell + command)
|
||||
val proot = LinuxRuntime.command(app, null, null, Environment.getExternalStorageDirectory(), null, env + shell + command, fakeRoot)
|
||||
return ProcessBuilder(proot).redirectErrorStream(true).apply {
|
||||
environment().apply {
|
||||
remove("LD_PRELOAD"); remove("LD_AUDIT"); remove("LD_LIBRARY_PATH")
|
||||
|
||||
@@ -73,6 +73,8 @@ object AgentSetup {
|
||||
Thread({ for ((step, command) in probes) probe(app, harness, step, command) }, "agent-checks").start()
|
||||
}
|
||||
|
||||
fun runsAsRoot(step: Step) = step == Step.INSTALL
|
||||
|
||||
/** Runs [step]'s action. [CONNECTION] is the app's own pairing flow, so the caller opens it. */
|
||||
fun run(context: Context, step: Step) {
|
||||
val app = context.applicationContext
|
||||
@@ -81,7 +83,7 @@ object AgentSetup {
|
||||
Step.CONNECTION -> return
|
||||
Step.INSTALL -> {
|
||||
listOf("sh", "-c", "set -e; export DEBIAN_FRONTEND=noninteractive; " +
|
||||
"dpkg --configure -a; apt-get update; apt-get -f install -y; " +
|
||||
"dpkg --configure -a; apt-get update || echo 'Some package sources could not be refreshed; continuing'; apt-get -f install -y; " +
|
||||
"apt-get install -y --no-install-recommends git gh adb curl ca-certificates python3; ${harness.install}")
|
||||
}
|
||||
Step.SIGN_IN -> harness.signIn
|
||||
@@ -97,7 +99,7 @@ object AgentSetup {
|
||||
val result = runCatching {
|
||||
installHelpers(app)
|
||||
runCatching { harness.prepare(LinuxRuntime.rootDir(app)) }
|
||||
val child = AgentHost.guest(app, command).start()
|
||||
val child = AgentHost.guest(app, command, fakeRoot = runsAsRoot(step)).start()
|
||||
val pid = AgentProcesses.pidOf(child)
|
||||
OrphanReaper.keep(pid)
|
||||
try {
|
||||
|
||||
@@ -139,15 +139,26 @@ public final class LinuxRuntime {
|
||||
public static List<String> command(Context context, File sessionRoot, File runtimeDir,
|
||||
File externalStorage, List<String> extraBinds,
|
||||
List<String> guestCommand) {
|
||||
return command(context, sessionRoot, runtimeDir, externalStorage, extraBinds, guestCommand, false);
|
||||
}
|
||||
|
||||
public static List<String> command(Context context, File sessionRoot, File runtimeDir,
|
||||
File externalStorage, List<String> extraBinds,
|
||||
List<String> guestCommand, boolean fakeRoot) {
|
||||
File root = rootDir(context);
|
||||
List<String> binds = binds(context, sessionRoot, runtimeDir, externalStorage, extraBinds);
|
||||
if (sessionRoot != null) lastBinds = binds;
|
||||
return commandWithBinds(context, root, binds, guestCommand);
|
||||
return commandWithBinds(context, root, binds, guestCommand, fakeRoot);
|
||||
}
|
||||
|
||||
public static List<String> commandWithBinds(Context context, File root, List<String> binds,
|
||||
List<String> guestCommand) {
|
||||
List<String> cmd = prootPrefix(context, root, "/root");
|
||||
return commandWithBinds(context, root, binds, guestCommand, false);
|
||||
}
|
||||
|
||||
public static List<String> commandWithBinds(Context context, File root, List<String> binds,
|
||||
List<String> guestCommand, boolean fakeRoot) {
|
||||
List<String> cmd = fakeRoot ? rootPrefix(context, root, "/root") : prootPrefix(context, root, "/root");
|
||||
for (String spec : binds) bind(cmd, spec);
|
||||
cmd.addAll(guestCommand);
|
||||
return cmd;
|
||||
@@ -170,6 +181,12 @@ public final class LinuxRuntime {
|
||||
return prootPrefix(context, root, cwd, false);
|
||||
}
|
||||
|
||||
public static List<String> rootPrefix(Context context, File root, String cwd) {
|
||||
List<String> cmd = prootPrefix(context, root, cwd, true);
|
||||
cmd.add(1, "--link2symlink");
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public static List<String> prootPrefix(Context context, File root, String cwd, boolean fakeRoot) {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add(prootBinary(context).getPath());
|
||||
|
||||
@@ -120,8 +120,7 @@ object RootSpawner {
|
||||
val builder = if (NativeGuest.forSession(context)) {
|
||||
NativeGuest.processBuilder(context, root, binds, guest, cwd)
|
||||
} else {
|
||||
val cmd = LinuxRuntime.prootPrefix(context, root, cwd, true)
|
||||
cmd.add(1, "--link2symlink")
|
||||
val cmd = LinuxRuntime.rootPrefix(context, root, cwd)
|
||||
binds.forEach { cmd.add("-b"); cmd.add(it) }
|
||||
cmd.addAll(guest)
|
||||
ProcessBuilder(cmd).directory(root).also { b ->
|
||||
|
||||
Reference in new issue
Block a user