feat: profile PRoot costs and test fast-path libraries without an APK rebuild (#1528)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-25 16:49:35 -04:00
1 parent aca4b5dd3e
commit 815b93db5f
17 files changed
+578 -10

No files matched your search

@@ -9,6 +9,8 @@ import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.text.AnnotatedString
import com.droiddeck.launcher.R
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.runtime.ProotFastPath
import com.droiddeck.launcher.session.SessionState
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.After
@@ -179,6 +181,31 @@ class AgentSecurityTest {
assertEquals(listOf("TEST=old", "STICKY=1"), AgentEnv.beginSession(context))
}
@Test fun fastPathLibraryIsValidatedAndSelectedForOneSession() {
AgentAccess.setCommandsEnabled(context, true)
val source = File(AgentEnv.inbox(context).apply { mkdirs() }, "libblfastpath.so")
source.writeText("wrong architecture")
refused("INVALID_LIBRARY") { AgentEnv.override(context, source.name) }
val header = ByteArray(64)
byteArrayOf(0x7f, 0x45, 0x4c, 0x46, 2, 1, 1).copyInto(header)
header[16] = 3
header[18] = 183.toByte()
source.writeBytes(header)
SessionState.running = true
try {
refused("SESSION_ACTIVE") { AgentEnv.override(context, source.name) }
} finally {
SessionState.running = false
}
val response = AgentEnv.override(context, source.name)
assertEquals(64, response.getString("sha256").length)
assertEquals(ProotFastPath.LIBRARY, AgentEnv.fastPathLibrary(context))
AgentEnv.beginSession(context)
assertEquals("/opt/droiddeck-agent/bin/libblfastpath.so", AgentEnv.fastPathLibrary(context))
AgentEnv.endSession(context)
assertEquals(ProotFastPath.LIBRARY, AgentEnv.fastPathLibrary(context))
}
@Test fun environmentValuesAreNotLogged() {
AgentAccess.setCommandsEnabled(context, true)
AgentEnv.set(context, listOf("CUSTOM=synthetic-private-value"), false)
@@ -0,0 +1,37 @@
package com.droiddeck.launcher.core
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class HostProcessTest {
@get:Rule val temporary = TemporaryFolder()
@Test fun appendsBothOutputStreamsToTheExistingLog() {
val windows = System.getProperty("os.name").orEmpty().startsWith("Windows")
val log = temporary.newFile("session.log").apply { writeText("guest output\n") }
val script = temporary.newFile(if (windows) "tracer.cmd" else "tracer.sh").apply {
writeText(if (windows) "@echo off\r\necho tracer stdout\r\necho tracer stderr>&2\r\n"
else "printf 'tracer stdout\\n'\nprintf 'tracer stderr\\n' >&2\n")
}
val finished = CountDownLatch(1)
var exitCode = -1
val shell = if (windows) "cmd.exe /c" else "/bin/sh"
HostProcess.start("$shell ${script.name}", null, temporary.root, {
exitCode = it
finished.countDown()
}, null, log)
assertTrue(finished.await(5, TimeUnit.SECONDS))
assertEquals(0, exitCode)
assertEquals(listOf("guest output", "tracer stdout", "tracer stderr"), log.readLines())
}
}