mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix(fex): signal return restores syscall state; CurseForge runs headless (#3040)
* fix(fex): signal return restores the interrupted syscall state A guest rt_sigreturn goes through FEX's syscall stub, which marks every static register as spilled. Returning to unchanged JIT code skipped the stub's reset, so later asynchronous signals skipped the register spill and guest handlers read stale registers. CoreCLR's GC suspension reads and redirects that context, which made x86-64 .NET programs fail with random access violations. Restore the value saved at signal entry. * fix(addons): run CurseForge headless from the addon browser, without a session - The CurseForge source starts the app in its own headless gamescope (droiddeck-headless, shared with the Battle.net Agent) instead of a hidden session: no SessionService, compositor output or ImageReader. - The helper's start keeps running until the app exits, so the app lives for as long as the addon browser holds that guest command; closing the dialog asks the app to quit, stops its process group and cancels the command, which ends the app, its gamescope and the guest. - An app the user already has open is reported busy and left alone. - Removes BackgroundSession and the CompositorHost start path it shared with SessionActivity, with their tests. * fix(addons): bind each CurseForge stop to its launch and keep the inspector URL out of logs A stop now only acts on the launch that registered it, so a late stop from a closed browser cannot end a newer launch, and the browser stops once. Command logs redact the inspector URL. The signal probe reports a sender thread that cannot start, sets ECX before the measured region and its test accepts a valid overshoot of the target count. * fix(fex): unblock the probe signal before sampling
This commit is contained in:
1 parent
6ef8e2274e
commit
527cb85867
21 files changed
+663
-415
No files matched your search
@@ -2846,7 +2846,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (!SessionState.running) {
|
||||
SessionEvents.transition(SessionPhase.STARTING_COMPOSITOR, "compositor.starting")
|
||||
}
|
||||
val output = CompositorHost.prepare(this)
|
||||
val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() }
|
||||
FileUtils.copyAsset(this, "wayland/keymap.xkb", File(runtimeDir, "keymap.xkb"))
|
||||
com.droiddeck.launcher.input.VrControllers.publish(this)
|
||||
|
||||
val turnip = TurnipDriver(this)
|
||||
com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "surface.driver-setup")
|
||||
if (!CompositorHost.isStarted) {
|
||||
CompositorHost.displayChoice = SessionPrefs.androidDriver(this)
|
||||
com.droiddeck.launcher.gpu.AutoDriverTrial.displayStarting(this, SessionPrefs.androidDriver(this))
|
||||
}
|
||||
val driverId = if (CompositorHost.isStarted) null else turnip.install()
|
||||
|
||||
val previous = SessionState.outputSize
|
||||
val live = windowOutputSize(holder.surfaceFrame.width(), holder.surfaceFrame.height())
|
||||
@@ -2873,7 +2883,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
pushCardboard(activeCardboard)
|
||||
WaylandCompositor.nativeSetCardboardPoseFile(File(filesDir, ".wayland-rt/droiddeck-headpose").path)
|
||||
com.droiddeck.launcher.glasses.SpatialTracking.attachPublisher(File(filesDir, ".wayland-rt/droiddeck-spatialpose").path)
|
||||
if (!SessionState.running) CompositorHost.logToSession(this)
|
||||
if (!SessionState.running) {
|
||||
val waylandLog = File(SessionPaths.beginOrCurrent(this), "wayland.log")
|
||||
WaylandCompositor.setSessionLogFile(waylandLog)
|
||||
try {
|
||||
android.system.Os.setenv("DD_WAYLAND_LOG", waylandLog.path, true)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "could not point the compositor's log at $waylandLog", e)
|
||||
}
|
||||
}
|
||||
val mode = hdrPrefMode()
|
||||
if (probe != null) {
|
||||
WaylandCompositor.nativeSetHdrDisplay(
|
||||
@@ -2893,8 +2911,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
)
|
||||
Log.i(TAG, "hdr: " + (if (tonemap) "tone-mapped (${probe.reason})" else if (capable) "available" else "unavailable") + " · display ${probe.formats.ifEmpty { "SDR" }}")
|
||||
}
|
||||
if (!SessionState.running) CompositorHost.applyHdr(this, mode)
|
||||
CompositorHost.start(this, output, holder.surface, size, refreshHz(holder), outputFpsLimit())
|
||||
if (!SessionState.running) {
|
||||
val on = SessionState.hdrCapable && SessionPrefs.hdr(this, mode)
|
||||
SessionState.hdr = on
|
||||
WaylandCompositor.nativeSetHdrOutput(on)
|
||||
WaylandCompositor.nativeSetZeroCopy(on || SessionPrefs.zeroCopy(this, mode))
|
||||
Log.i(TAG, "hdr: " + (if (on) "on" else "off") + " for this $mode session")
|
||||
}
|
||||
com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "compositor.start driver=$driverId")
|
||||
CompositorHost.startOrAttach(
|
||||
this, holder.surface, runtimeDir.path,
|
||||
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), outputFpsLimit(),
|
||||
)
|
||||
onOutputAttached(holder)
|
||||
if (SessionState.running && size != previous) {
|
||||
Log.i(TAG, "output resized: ${previous.first}x${previous.second} -> ${size.first}x${size.second} on a new surface")
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.agent.AgentException
|
||||
import com.droiddeck.launcher.agent.AgentGuest
|
||||
import com.droiddeck.launcher.stores.battlenet.BattleNetInstall
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
object CurseForgeApp {
|
||||
const val NAME = "CurseForge"
|
||||
const val FEED = "https://curseforge.overwolf.com/electron/linux/latest-linux.yml"
|
||||
internal const val WOW = 1
|
||||
const val HELPER = "/usr/local/bin/droiddeck-curseforge"
|
||||
internal const val AGENT = "/usr/local/bin/droiddeck-agent"
|
||||
private const val READY_MS = 120_000L
|
||||
private const val INSTALL_MS = 300_000L
|
||||
|
||||
enum class Start { READY, BUSY, NO_DISPLAY, FAILED }
|
||||
enum class Start { READY, BUSY, FAILED }
|
||||
|
||||
class Started(val state: Start, val inspector: String? = null)
|
||||
|
||||
private val INSPECTOR = Regex("ws://127\\.0\\.0\\.1:[0-9]{4,5}/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
||||
internal val INSPECTOR = Regex("ws://127\\.0\\.0\\.1:[0-9]{4,5}/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
||||
|
||||
class Failure(message: String, val code: String? = null) : Exception(message) {
|
||||
val gone get() = code == "DEVTOOLS_UNREACHABLE"
|
||||
@@ -31,14 +35,19 @@ object CurseForgeApp {
|
||||
|
||||
internal fun dir(app: UserApps.App): String? = app.args.firstOrNull()?.takeIf { it.startsWith("/") }
|
||||
|
||||
fun holdArgs(app: UserApps.App): List<String>? = dir(app)?.let { listOf("hold", it) }
|
||||
internal fun helperArgv(command: String, dir: String): List<String> = listOf(HELPER, command, dir)
|
||||
|
||||
internal fun evalArgv(inspector: String, expression: String, timeoutMs: Long): List<String> =
|
||||
listOf(AGENT, "--cdp-inspector", inspector, (timeoutMs / 1000.0).toString(), expression)
|
||||
|
||||
internal fun lastJson(lines: List<String>): JSONObject? =
|
||||
lines.asReversed().firstNotNullOfOrNull { line -> runCatching { JSONObject(line.trim()) }.getOrNull() }
|
||||
|
||||
internal fun inspectorUrl(stdout: String): String? = stdout.lineSequence().map { it.trim() }.lastOrNull { INSPECTOR.matches(it) }
|
||||
|
||||
internal fun startState(exitCode: Int): Start = when (exitCode) {
|
||||
0 -> Start.READY
|
||||
3 -> Start.BUSY
|
||||
4 -> Start.NO_DISPLAY
|
||||
else -> Start.FAILED
|
||||
}
|
||||
|
||||
@@ -137,47 +146,75 @@ object CurseForgeApp {
|
||||
return (0 until list.length()).mapNotNull { list.opt(it)?.toString()?.takeIf { id -> id.isNotBlank() && id != "null" } }.toSet()
|
||||
}
|
||||
|
||||
private fun call(context: Context, inspector: String, service: String, method: String, args: JSONArray?, timeoutMs: Long, pick: String = "r => r"): Any? {
|
||||
val request = JSONObject().put("kind", "cdp").put("inspector", inspector).put("commandLineApi", true)
|
||||
.put("expression", expression(service, method, args, pick)).put("timeout", timeoutMs / 1000.0)
|
||||
return unwrap(AgentGuest.call(context, request, timeoutMs + 3_000, trusted = true))
|
||||
internal var guest: (Context, List<String>, AtomicBoolean?, (String) -> Unit) -> Int = { context, argv, cancelled, onLine ->
|
||||
GuestCommand.run(context, argv, logName = "curseforge", extraBinds = BattleNetInstall.binds(context), fastPath = true,
|
||||
cancelled = cancelled, redact = INSPECTOR, onLine = onLine)
|
||||
}
|
||||
|
||||
private fun helper(context: Context, command: String, dir: String, timeoutMs: Long): JSONObject? {
|
||||
val request = JSONObject().put("kind", "exec").put("argv", JSONArray(listOf(HELPER, command, dir))).put("timeout", timeoutMs / 1000.0)
|
||||
return runCatching { AgentGuest.call(context, request, timeoutMs + 5_000, trusted = true) }.getOrNull()
|
||||
private val holds = ConcurrentHashMap<String, AtomicBoolean>()
|
||||
|
||||
private fun lines(context: Context, argv: List<String>): List<String> {
|
||||
val out = ArrayList<String>()
|
||||
guest(context, argv, null) { out += it }
|
||||
return out
|
||||
}
|
||||
|
||||
fun start(context: Context, app: UserApps.App): Started {
|
||||
private fun call(context: Context, inspector: String, service: String, method: String, args: JSONArray?, timeoutMs: Long, pick: String = "r => r"): Any? =
|
||||
unwrap(lastJson(lines(context, evalArgv(inspector, expression(service, method, args, pick), timeoutMs))) ?: throw Failure("CurseForge gave no answer"))
|
||||
|
||||
private sealed class Launch {
|
||||
class Url(val inspector: String) : Launch()
|
||||
class Exit(val code: Int) : Launch()
|
||||
}
|
||||
|
||||
private fun launch(context: Context, dir: String, hold: AtomicBoolean): Launch? {
|
||||
val first = LinkedBlockingQueue<Launch>()
|
||||
Thread({
|
||||
val code = runCatching {
|
||||
guest(context, helperArgv("start", dir), hold) { line -> inspectorUrl(line)?.let { first.offer(Launch.Url(it)) } }
|
||||
}.getOrDefault(-1)
|
||||
first.offer(Launch.Exit(code))
|
||||
}, "curseforge-headless").apply { isDaemon = true; start() }
|
||||
return first.poll(READY_MS, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
|
||||
fun start(context: Context, app: UserApps.App, hold: AtomicBoolean): Started {
|
||||
val dir = dir(app) ?: return Started(Start.FAILED)
|
||||
val answer = helper(context, "start", dir, 90_000)
|
||||
if (answer == null || !answer.optBoolean("ok") || answer.optBoolean("timedOut")) {
|
||||
stop(context, app, null)
|
||||
return Started(Start.FAILED)
|
||||
if (hold.get()) return Started(Start.FAILED)
|
||||
holds.put(dir, hold)?.takeIf { it !== hold }?.let {
|
||||
it.set(true)
|
||||
runCatching { lines(context, helperArgv("stop", dir)) }
|
||||
}
|
||||
val state = startState(answer.optInt("exitCode", -1))
|
||||
if (state == Start.BUSY || state == Start.NO_DISPLAY) return Started(state)
|
||||
val inspector = inspectorUrl(answer.optJSONObject("stdout")?.optString("text").orEmpty())
|
||||
if (state != Start.READY || inspector == null) {
|
||||
stop(context, app, null)
|
||||
val inspector = when (val first = launch(context, dir, hold)) {
|
||||
is Launch.Url -> first.inspector
|
||||
is Launch.Exit -> if (startState(first.code) == Start.BUSY) {
|
||||
holds.remove(dir, hold)
|
||||
return Started(Start.BUSY)
|
||||
} else null
|
||||
null -> null
|
||||
}
|
||||
if (inspector == null) {
|
||||
stop(context, app, null, hold)
|
||||
return Started(Start.FAILED)
|
||||
}
|
||||
val deadline = System.currentTimeMillis() + READY_MS
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
val ready = runCatching { call(context, inspector, "InstalledProjectsAppService", "installAddon", null, 10_000) }
|
||||
if (ready.isSuccess) return Started(Start.READY, inspector)
|
||||
val error = ready.exceptionOrNull()
|
||||
if (error is AgentException && error.code == "NO_ACTIVE_SESSION") break
|
||||
while (System.currentTimeMillis() < deadline && !hold.get()) {
|
||||
if (runCatching { call(context, inspector, "InstalledProjectsAppService", "installAddon", null, 10_000) }.isSuccess) return Started(Start.READY, inspector)
|
||||
Thread.sleep(1_000)
|
||||
}
|
||||
stop(context, app, inspector)
|
||||
stop(context, app, inspector, hold)
|
||||
return Started(Start.FAILED)
|
||||
}
|
||||
|
||||
fun stop(context: Context, app: UserApps.App, inspector: String?) {
|
||||
fun stop(context: Context, app: UserApps.App, inspector: String?, hold: AtomicBoolean) {
|
||||
val dir = dir(app) ?: return
|
||||
if (holds[dir] !== hold) {
|
||||
hold.set(true)
|
||||
return
|
||||
}
|
||||
if (inspector != null) runCatching { call(context, inspector, "CoreService", "shutdown", JSONArray(), 30_000, "r => true") }
|
||||
helper(context, "stop", dir, 30_000)
|
||||
hold.set(true)
|
||||
if (holds.remove(dir, hold)) runCatching { lines(context, helperArgv("stop", dir)) }
|
||||
}
|
||||
|
||||
private fun connect(context: Context, inspector: String) {
|
||||
@@ -207,7 +244,7 @@ object CurseForgeApp {
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
val listed = runCatching { installed(context, inspector, guid) }
|
||||
val error = listed.exceptionOrNull()
|
||||
if (error is Failure && error.gone || error is AgentException && error.code == "NO_ACTIVE_SESSION") throw error
|
||||
if (error is Failure && error.gone) throw error
|
||||
if (projectId in listed.getOrDefault(emptySet())) return true
|
||||
Thread.sleep(1_000)
|
||||
}
|
||||
|
||||
@@ -14,20 +14,22 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
object GuestCommand {
|
||||
fun run(context: Context, argv: List<String>, fakeRoot: Boolean = false, logName: String? = null,
|
||||
linkDir: File? = null, extraBinds: List<String>? = null, fastPath: Boolean = false, cancelled: AtomicBoolean? = null,
|
||||
onLine: (String) -> Unit): Int {
|
||||
redact: Regex? = null, onLine: (String) -> Unit): Int {
|
||||
val log = logName?.let {
|
||||
try {
|
||||
File(File(LinuxRuntime.logDir(context), SessionPaths.TOOLS_DIR).apply { mkdirs() }, "$it.log").printWriter()
|
||||
} catch (e: Exception) { null }
|
||||
}
|
||||
log?.println("== ${java.util.Date()} ${argv.joinToString(" ")}")
|
||||
log?.println("== ${java.util.Date()} ${redacted(argv.joinToString(" "), redact)}")
|
||||
try {
|
||||
return runLogged(context, argv, fakeRoot, linkDir, extraBinds, fastPath, cancelled) { line -> log?.println(line); log?.flush(); onLine(line) }
|
||||
return runLogged(context, argv, fakeRoot, linkDir, extraBinds, fastPath, cancelled) { line -> log?.println(redacted(line, redact)); log?.flush(); onLine(line) }
|
||||
} finally {
|
||||
log?.close()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun redacted(text: String, redact: Regex?): String = redact?.replace(text, "<redacted>") ?: text
|
||||
|
||||
private fun runLogged(context: Context, argv: List<String>, fakeRoot: Boolean, linkDir: File?, extraBinds: List<String>?,
|
||||
fastPath: Boolean, cancelled: AtomicBoolean?, onLine: (String) -> Unit): Int {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PixelFormat
|
||||
import android.media.ImageReader
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.agent.AgentGuest
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntimeInstaller
|
||||
import com.droiddeck.launcher.storage.StorageState
|
||||
import com.droiddeck.launcher.wayland.CompositorHost
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
object BackgroundSession {
|
||||
private const val TAG = "BackgroundSession"
|
||||
private const val WIDTH = 1280
|
||||
private const val HEIGHT = 720
|
||||
private const val REFRESH_HZ = 60f
|
||||
private const val BEGIN_MS = 30_000L
|
||||
private const val AGENT_MS = 120_000L
|
||||
private const val STOP_MS = 30_000L
|
||||
private val ended = setOf(SessionPhase.IDLE, SessionPhase.FAILED)
|
||||
private val main by lazy { Handler(Looper.getMainLooper()) }
|
||||
private var reader: ImageReader? = null
|
||||
|
||||
fun start(context: Context, program: String, args: List<String>): String? {
|
||||
val app = context.applicationContext
|
||||
val claim = AtomicBoolean(false)
|
||||
val began = CountDownLatch(1)
|
||||
var own: String? = null
|
||||
main.post {
|
||||
if (claim.compareAndSet(false, true)) {
|
||||
own = runCatching { begin(app, program, args) }
|
||||
.onFailure { Log.w(TAG, "could not start a hidden session for $program", it) }
|
||||
.getOrNull()
|
||||
}
|
||||
began.countDown()
|
||||
}
|
||||
if (!began.await(BEGIN_MS, TimeUnit.MILLISECONDS) && claim.compareAndSet(false, true)) return null
|
||||
began.await()
|
||||
val session = own ?: return null
|
||||
val deadline = System.currentTimeMillis() + AGENT_MS
|
||||
val settle = System.currentTimeMillis() + 5_000
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
if (SessionState.sessionId != session) return null
|
||||
if (SessionState.running && AgentGuest.hello(app) != null && SessionState.sessionId == session) return session
|
||||
if (SessionState.phase == SessionPhase.FAILED) break
|
||||
if (!SessionState.running && SessionState.phase in ended && System.currentTimeMillis() > settle) break
|
||||
Thread.sleep(250)
|
||||
}
|
||||
stop(app, session)
|
||||
return null
|
||||
}
|
||||
|
||||
fun stop(context: Context, session: String) {
|
||||
val app = context.applicationContext
|
||||
if (SessionState.sessionId != session) return
|
||||
main.post { if (SessionState.sessionId == session) SessionService.stop(app) }
|
||||
val deadline = System.currentTimeMillis() + STOP_MS
|
||||
while (live(session) && System.currentTimeMillis() < deadline) Thread.sleep(250)
|
||||
if (!live(session)) {
|
||||
main.post { release() }
|
||||
return
|
||||
}
|
||||
Thread {
|
||||
while (live(session)) Thread.sleep(1_000)
|
||||
main.post { release() }
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun live(session: String) =
|
||||
SessionState.sessionId == session && (SessionState.running || SessionState.phase !in ended)
|
||||
|
||||
private fun begin(context: Context, program: String, args: List<String>): String? {
|
||||
if (SessionState.running || SessionState.phase !in ended || LinuxRuntimeInstaller.isBusy() ||
|
||||
SessionState.installing != null || StorageState.cleaning) return null
|
||||
release()
|
||||
SessionEvents.begin(context, SessionService.MODE_RUN, SessionPaths.label(SessionService.MODE_RUN, program))
|
||||
val session = SessionState.sessionId ?: return null
|
||||
SessionState.stopRequested = false
|
||||
SessionEvents.transition(SessionPhase.STARTING_COMPOSITOR, "compositor.starting")
|
||||
var requested = false
|
||||
try {
|
||||
val output = CompositorHost.prepare(context)
|
||||
val size = WIDTH to HEIGHT
|
||||
SessionState.outputSize = size
|
||||
SessionState.refreshHz = REFRESH_HZ
|
||||
CompositorHost.logToSession(context)
|
||||
CompositorHost.applyHdr(context, SessionPrefs.prefMode(SessionService.MODE_RUN))
|
||||
val offscreen = ImageReader.newInstance(WIDTH, HEIGHT, PixelFormat.RGBA_8888, 2)
|
||||
reader = offscreen
|
||||
offscreen.setOnImageAvailableListener({ it.acquireLatestImage()?.close() }, main)
|
||||
CompositorHost.start(context, output, offscreen.surface, size, REFRESH_HZ, 0)
|
||||
CompositorHost.detach(offscreen.surface)
|
||||
SessionEvents.record("compositor.started")
|
||||
SessionEvents.transition(SessionPhase.STARTING_GUEST, "guest.starting")
|
||||
requested = true
|
||||
SessionService.start(context, SessionService.MODE_RUN, program, programArgs = args.toTypedArray())
|
||||
return session
|
||||
} catch (e: Exception) {
|
||||
if (requested) SessionService.stop(context)
|
||||
if (!SessionState.running) {
|
||||
reader?.close()
|
||||
reader = null
|
||||
SessionEvents.transition(SessionPhase.FAILED, "hidden.failed", mapOf("error" to e.toString()))
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private fun release() {
|
||||
if (SessionState.running) return
|
||||
reader?.close()
|
||||
reader = null
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,7 @@ object SessionFiles {
|
||||
"usr/local/bin/droiddeck-appimage-run" to "usr/local/bin/droiddeck-appimage-run",
|
||||
"usr/local/bin/droiddeck-appimage-exec" to "usr/local/bin/droiddeck-appimage-exec",
|
||||
"usr/local/bin/droiddeck-curseforge" to "usr/local/bin/droiddeck-curseforge",
|
||||
"usr/local/bin/droiddeck-headless" to "usr/local/bin/droiddeck-headless",
|
||||
"usr/local/bin/droiddeck-script-run" to "usr/local/bin/droiddeck-script-run",
|
||||
"usr/local/bin/droiddeck-open" to "usr/local/bin/droiddeck-open",
|
||||
"usr/local/bin/droiddeck-proton-run" to "usr/local/bin/droiddeck-proton-run",
|
||||
|
||||
@@ -330,7 +330,7 @@ public final class GogDownloadManager {
|
||||
rc = GuestCommand.INSTANCE.run(ctx, Arrays.asList(
|
||||
"/usr/local/bin/droiddeck-innoextract", "--gog", "--silent",
|
||||
"-d", guestDir, guestSetup),
|
||||
false, "gog-innoextract", null, null, false, cancelled,
|
||||
false, "gog-innoextract", null, null, false, cancelled, null,
|
||||
line -> { cb.onLog("gog innoextract: " + line); return kotlin.Unit.INSTANCE; });
|
||||
} catch (Exception e) {
|
||||
throw new InstallException("The installer could not be extracted: " + e.getClass().getSimpleName());
|
||||
|
||||
@@ -67,14 +67,13 @@ import com.droiddeck.launcher.runtime.CurseForgeApp
|
||||
import com.droiddeck.launcher.runtime.UserApps
|
||||
import com.droiddeck.launcher.runtime.WowAddonCatalog
|
||||
import com.droiddeck.launcher.runtime.WowAddons
|
||||
import com.droiddeck.launcher.session.BackgroundSession
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
private class AddonResults {
|
||||
val items = mutableStateListOf<WowAddonCatalog.Addon>()
|
||||
@@ -95,10 +94,7 @@ private class CurseLink(val app: UserApps.App) {
|
||||
|
||||
private val lock = Object()
|
||||
@Volatile private var closed = false
|
||||
private var held = false
|
||||
private var ownSession: String? = null
|
||||
private var started = false
|
||||
@Volatile private var launching = false
|
||||
@Volatile private var hold: AtomicBoolean? = null
|
||||
@Volatile private var inspector: String? = null
|
||||
private val guids = HashMap<String, String>()
|
||||
|
||||
@@ -119,29 +115,13 @@ private class CurseLink(val app: UserApps.App) {
|
||||
|
||||
private fun link(context: Context, target: WowAddons.Target): Linked {
|
||||
if (closed) throw CurseState()
|
||||
if (!SessionState.running) {
|
||||
started = false
|
||||
launching = false
|
||||
held = false
|
||||
ownSession = null
|
||||
inspector = null
|
||||
guids.clear()
|
||||
val args = CurseForgeApp.holdArgs(app) ?: throw CurseState()
|
||||
ownSession = BackgroundSession.start(context, CurseForgeApp.HELPER, args) ?: throw CurseState()
|
||||
}
|
||||
if (closed) throw CurseState()
|
||||
if (!held) {
|
||||
held = true
|
||||
SessionService.holdForSignIn(context, true)
|
||||
}
|
||||
val awake = System.currentTimeMillis() + 30_000
|
||||
while ((SessionState.suspended || SessionState.suspending) && System.currentTimeMillis() < awake) Thread.sleep(250)
|
||||
val url = inspector ?: run {
|
||||
launching = true
|
||||
val done = CurseForgeApp.start(context, app)
|
||||
val launch = AtomicBoolean(false)
|
||||
hold = launch
|
||||
if (closed) throw CurseState()
|
||||
val done = CurseForgeApp.start(context, app, launch)
|
||||
when (done.state) {
|
||||
CurseForgeApp.Start.READY -> {
|
||||
started = true
|
||||
inspector = done.inspector
|
||||
done.inspector ?: throw CurseState()
|
||||
}
|
||||
@@ -160,17 +140,11 @@ private class CurseLink(val app: UserApps.App) {
|
||||
|
||||
fun close(context: Context) {
|
||||
closed = true
|
||||
val launch = hold ?: return
|
||||
Thread {
|
||||
if (launching) CurseForgeApp.stop(context, app, inspector)
|
||||
CurseForgeApp.stop(context, app, inspector, launch)
|
||||
synchronized(lock) {
|
||||
if (started) CurseForgeApp.stop(context, app, inspector)
|
||||
val owned = ownSession
|
||||
if (owned != null) BackgroundSession.stop(context, owned)
|
||||
else if (held) SessionService.holdForSignIn(context, false)
|
||||
started = false
|
||||
launching = false
|
||||
ownSession = null
|
||||
held = false
|
||||
hold = null
|
||||
inspector = null
|
||||
}
|
||||
}.start()
|
||||
|
||||
@@ -10,8 +10,6 @@ import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
|
||||
object CompositorHost {
|
||||
private const val TAG = "DroidDeck"
|
||||
|
||||
@Volatile
|
||||
private var started = false
|
||||
|
||||
@@ -57,52 +55,6 @@ object CompositorHost {
|
||||
}
|
||||
}
|
||||
|
||||
class Output internal constructor(
|
||||
internal val runtimeDir: java.io.File,
|
||||
internal val turnip: com.droiddeck.launcher.gpu.TurnipDriver,
|
||||
internal val driverId: String?,
|
||||
)
|
||||
|
||||
fun prepare(context: android.content.Context): Output {
|
||||
val runtimeDir = java.io.File(context.filesDir, ".wayland-rt").apply { mkdirs() }
|
||||
com.droiddeck.launcher.core.FileUtils.copyAsset(context, "wayland/keymap.xkb", java.io.File(runtimeDir, "keymap.xkb"))
|
||||
com.droiddeck.launcher.input.VrControllers.publish(context)
|
||||
val turnip = com.droiddeck.launcher.gpu.TurnipDriver(context)
|
||||
com.droiddeck.launcher.gpu.DriverSetupLog.write(context, "surface.driver-setup")
|
||||
if (!started) {
|
||||
displayChoice = SessionPrefs.androidDriver(context)
|
||||
com.droiddeck.launcher.gpu.AutoDriverTrial.displayStarting(context, SessionPrefs.androidDriver(context))
|
||||
}
|
||||
return Output(runtimeDir, turnip, if (started) null else turnip.install())
|
||||
}
|
||||
|
||||
fun logToSession(context: android.content.Context) {
|
||||
val waylandLog = java.io.File(com.droiddeck.launcher.session.SessionPaths.beginOrCurrent(context), "wayland.log")
|
||||
WaylandCompositor.setSessionLogFile(waylandLog)
|
||||
try {
|
||||
android.system.Os.setenv("DD_WAYLAND_LOG", waylandLog.path, true)
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.w(TAG, "could not point the compositor's log at $waylandLog", e)
|
||||
}
|
||||
}
|
||||
|
||||
fun applyHdr(context: android.content.Context, mode: String) {
|
||||
val on = SessionState.hdrCapable && SessionPrefs.hdr(context, mode)
|
||||
SessionState.hdr = on
|
||||
WaylandCompositor.nativeSetHdrOutput(on)
|
||||
WaylandCompositor.nativeSetZeroCopy(on || SessionPrefs.zeroCopy(context, mode))
|
||||
android.util.Log.i(TAG, "hdr: " + (if (on) "on" else "off") + " for this $mode session")
|
||||
}
|
||||
|
||||
fun start(context: android.content.Context, output: Output, surface: Surface, size: Pair<Int, Int>, refreshHz: Float, fpsLimit: Int): Boolean {
|
||||
com.droiddeck.launcher.gpu.DriverSetupLog.write(context, "compositor.start driver=${output.driverId}")
|
||||
return startOrAttach(
|
||||
context, surface, output.runtimeDir.path,
|
||||
output.driverId?.let { output.turnip.driverPath(it) }, output.driverId?.let { output.turnip.libraryName(it) },
|
||||
context.applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz, fpsLimit,
|
||||
)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun startOrAttach(
|
||||
context: android.content.Context,
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.After
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
@@ -21,6 +22,47 @@ import java.io.File
|
||||
class CurseForgeAppTest {
|
||||
@get:Rule val temp = TemporaryFolder()
|
||||
|
||||
private val original = CurseForgeApp.guest
|
||||
private val url = "ws://127.0.0.1:43117/0f8fad5b-d9cb-469f-a165-70867728950e"
|
||||
private val app = UserApps.App("appimage:c", UserApps.Kind.APPIMAGE, "CurseForge", null, null, AppImageManager.LAUNCHER, listOf("/root/apps/curseforge"), feed = CurseForgeApp.FEED)
|
||||
|
||||
@After
|
||||
fun restoreGuest() {
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
launches.forEach { CurseForgeApp.stop(context, app, null, it) }
|
||||
holder.get()?.set(true)
|
||||
CurseForgeApp.guest = original
|
||||
}
|
||||
|
||||
private val launches = mutableListOf<java.util.concurrent.atomic.AtomicBoolean>()
|
||||
|
||||
private fun launch(): java.util.concurrent.atomic.AtomicBoolean = java.util.concurrent.atomic.AtomicBoolean(false).also { launches += it }
|
||||
|
||||
private val holder = java.util.concurrent.atomic.AtomicReference<java.util.concurrent.atomic.AtomicBoolean?>()
|
||||
private val released = java.util.concurrent.CountDownLatch(1)
|
||||
|
||||
private fun fakeGuest(startExit: Int, ready: Boolean = true): MutableList<List<String>> {
|
||||
val calls = java.util.Collections.synchronizedList(mutableListOf<List<String>>())
|
||||
CurseForgeApp.guest = { _, argv, cancelled, onLine ->
|
||||
calls += argv
|
||||
when {
|
||||
argv[0] == CurseForgeApp.HELPER && argv[1] == "start" -> {
|
||||
if (startExit == 0) {
|
||||
holder.set(cancelled)
|
||||
onLine(url)
|
||||
while (cancelled?.get() != true) Thread.sleep(10)
|
||||
released.countDown()
|
||||
} else onLine("busy")
|
||||
startExit
|
||||
}
|
||||
argv[0] == CurseForgeApp.HELPER -> 0
|
||||
ready -> { onLine(JSONObject().put("ok", true).put("value", """{"value":true}""").toString()); 0 }
|
||||
else -> { onLine(JSONObject().put("ok", false).put("error", JSONObject().put("code", "DEVTOOLS_UNREACHABLE").put("message", "no")).toString()); 0 }
|
||||
}
|
||||
}
|
||||
return calls
|
||||
}
|
||||
|
||||
private val search = """{"success":true,"injectedCount":0,
|
||||
"pagination":{"index":0,"pageSize":20,"resultCount":20,"totalCount":150},
|
||||
"mods":[
|
||||
@@ -129,7 +171,7 @@ class CurseForgeAppTest {
|
||||
assertEquals(emptySet<String>(), CurseForgeApp.projectIds(JSONObject()))
|
||||
assertEquals(CurseForgeApp.Start.READY, CurseForgeApp.startState(0))
|
||||
assertEquals(CurseForgeApp.Start.BUSY, CurseForgeApp.startState(3))
|
||||
assertEquals(CurseForgeApp.Start.NO_DISPLAY, CurseForgeApp.startState(4))
|
||||
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.startState(4))
|
||||
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.startState(5))
|
||||
}
|
||||
|
||||
@@ -158,4 +200,102 @@ class CurseForgeAppTest {
|
||||
assertEquals(File(root, target.flavor), WowAddons.flavorDir(target))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theAppStartsInTheGuestWithoutASessionAndIsAskedThroughItsInspector() {
|
||||
val calls = fakeGuest(0)
|
||||
val started = CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), app, launch())
|
||||
assertEquals(CurseForgeApp.Start.READY, started.state)
|
||||
assertEquals(url, started.inspector)
|
||||
assertEquals(listOf(CurseForgeApp.HELPER, "start", "/root/apps/curseforge"), calls.first())
|
||||
val probe = calls[1]
|
||||
assertEquals(listOf(CurseForgeApp.AGENT, "--cdp-inspector", url), probe.take(3))
|
||||
assertEquals("10.0", probe[3])
|
||||
assertTrue(probe[4].contains("InstalledProjectsAppService"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theLaunchLivesUntilItIsStopped() {
|
||||
fakeGuest(0)
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val hold = launch()
|
||||
assertEquals(CurseForgeApp.Start.READY, CurseForgeApp.start(context, app, hold).state)
|
||||
assertEquals(false, holder.get()?.get())
|
||||
assertEquals(1L, released.count)
|
||||
CurseForgeApp.stop(context, app, url, hold)
|
||||
assertTrue(released.await(5, java.util.concurrent.TimeUnit.SECONDS))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anAppThatIsAlreadyOpenIsNeitherUsedNorStopped() {
|
||||
val calls = fakeGuest(3)
|
||||
assertEquals(CurseForgeApp.Start.BUSY, CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), app, launch()).state)
|
||||
assertEquals(listOf(listOf(CurseForgeApp.HELPER, "start", "/root/apps/curseforge")), calls)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stoppingAsksTheAppToQuitThenStopsItsHeadlessLaunchOnce() {
|
||||
val calls = fakeGuest(0)
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val hold = launch()
|
||||
CurseForgeApp.start(context, app, hold)
|
||||
calls.clear()
|
||||
CurseForgeApp.stop(context, app, url, hold)
|
||||
assertEquals(CurseForgeApp.AGENT, calls[0][0])
|
||||
assertTrue(calls[0][4].contains("shutdown"))
|
||||
assertEquals(listOf(CurseForgeApp.HELPER, "stop", "/root/apps/curseforge"), calls[1])
|
||||
assertTrue(hold.get())
|
||||
calls.clear()
|
||||
CurseForgeApp.stop(context, app, url, hold)
|
||||
assertTrue(calls.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aLateStopLeavesTheNewerLaunchRunning() {
|
||||
val calls = fakeGuest(0)
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val old = launch()
|
||||
val newer = launch()
|
||||
CurseForgeApp.start(context, app, old)
|
||||
CurseForgeApp.start(context, app, newer)
|
||||
assertTrue(old.get())
|
||||
calls.clear()
|
||||
CurseForgeApp.stop(context, app, url, old)
|
||||
assertTrue(calls.isEmpty())
|
||||
assertEquals(false, newer.get())
|
||||
CurseForgeApp.stop(context, app, null, newer)
|
||||
assertEquals(listOf(listOf(CurseForgeApp.HELPER, "stop", "/root/apps/curseforge")), calls)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aStoppedLaunchNeverStarts() {
|
||||
val calls = fakeGuest(0)
|
||||
val hold = launch().apply { set(true) }
|
||||
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), app, hold).state)
|
||||
assertTrue(calls.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anAppWithoutADirectoryIsNeverLaunched() {
|
||||
val calls = fakeGuest(0)
|
||||
val bare = UserApps.App("appimage:d", UserApps.Kind.APPIMAGE, "CurseForge", null, null, AppImageManager.LAUNCHER, emptyList(), feed = CurseForgeApp.FEED)
|
||||
val hold = launch()
|
||||
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), bare, hold).state)
|
||||
CurseForgeApp.stop(org.robolectric.RuntimeEnvironment.getApplication(), bare, url, hold)
|
||||
assertTrue(calls.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theInspectorUrlIsRedactedFromCommandLogs() {
|
||||
val line = CurseForgeApp.evalArgv(url, "x", 1_000).joinToString(" ")
|
||||
assertTrue(line.contains(url))
|
||||
assertTrue(!GuestCommand.redacted(line, CurseForgeApp.INSPECTOR).contains("127.0.0.1"))
|
||||
assertTrue(!GuestCommand.redacted(url, CurseForgeApp.INSPECTOR).contains(url))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theAgentAnswerIsTheLastJsonLine() {
|
||||
assertEquals("a", CurseForgeApp.lastJson(listOf("noise", """{"v":"a"}""", "== done"))?.getString("v"))
|
||||
assertNull(CurseForgeApp.lastJson(listOf("noise")))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user