mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Bind cold Library launches to the verified frames session
This commit is contained in:
1 parent
d1ffe46ce0
commit
d59154a85d
5 files changed
+67
-14
No files matched your search
@@ -1101,6 +1101,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
} else {
|
||||
putExtra(SessionService.EXTRA_STEAM_URL,
|
||||
com.droiddeck.launcher.frontend.GameLaunchLink.steamUrl(game.gameIdString))
|
||||
putExtra(SessionService.EXTRA_FRONTEND_STEAM_GAME, true)
|
||||
}
|
||||
}
|
||||
.playing(game), steamSession = true)
|
||||
|
||||
@@ -3119,6 +3119,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
intent.getStringArrayExtra(SessionService.EXTRA_PROGRAM_ARGS),
|
||||
intent.getStringExtra(SessionService.EXTRA_GAME_ID),
|
||||
sessionActivityDisplayId,
|
||||
frontendSteamGame = intent.getBooleanExtra(SessionService.EXTRA_FRONTEND_STEAM_GAME, false),
|
||||
)
|
||||
intent.getStringExtra(EXTRA_PLAYED_GAME)?.let { com.droiddeck.launcher.frontend.Library.recordPlayed(this, it) }
|
||||
}
|
||||
|
||||
@@ -25,7 +25,10 @@ internal object FrameAcquireWorkerProbe {
|
||||
internal const val RECEIPT_BYTES = Int.SIZE_BYTES + Long.SIZE_BYTES
|
||||
private const val TTL_MS = 90_000L
|
||||
|
||||
internal data class Ticket(val owner: Int, val root: File, val configuredRoot: File, val binary: File, val expected: ByteArray, val expires: Long)
|
||||
internal data class Ticket(
|
||||
val owner: Int, val root: File, val configuredRoot: File, val binary: File,
|
||||
val expected: ByteArray, val expires: Long, val steamGameUrl: String?,
|
||||
)
|
||||
internal data class Qualified(val ticket: Ticket, val dev: Long, val ino: Long, val mtime: Long, val ctime: Long)
|
||||
private var intent: Ticket? = null
|
||||
private var nativeOwner = 0
|
||||
@@ -71,8 +74,15 @@ internal object FrameAcquireWorkerProbe {
|
||||
|
||||
// Compute asset identity outside SessionService's stop lock and before a worker
|
||||
// exists. The resulting ticket still has to be assigned to that exact owner.
|
||||
internal fun prepare(context: Context): Ticket? {
|
||||
if (!available(context) || !WaylandCompositor.frameWorkerProbeEnabled()) return null
|
||||
private const val STEAM_RUN_PREFIX = "steam://rungameid/"
|
||||
|
||||
internal fun permittedLaunch(url: String?, frontendGame: Boolean): Boolean =
|
||||
if (url == null) !frontendGame else frontendGame && url.startsWith(STEAM_RUN_PREFIX) &&
|
||||
com.droiddeck.launcher.frontend.GameLaunchLink.validId(url.removePrefix(STEAM_RUN_PREFIX))
|
||||
|
||||
internal fun prepare(context: Context, steamGameUrl: String?, frontendGame: Boolean): Ticket? {
|
||||
if (!permittedLaunch(steamGameUrl, frontendGame) ||
|
||||
!available(context) || !WaylandCompositor.frameWorkerProbeEnabled()) return null
|
||||
return runCatching {
|
||||
val configuredRoot = LinuxRuntime.rootDir(context).absoluteFile
|
||||
val root = configuredRoot.canonicalFile
|
||||
@@ -84,7 +94,7 @@ internal object FrameAcquireWorkerProbe {
|
||||
val signedScript = context.assets.open("linuxfs" + SESSION_SCRIPT).use { digest(it, 1024L * 1024L) }
|
||||
require(MessageDigest.isEqual(stagedScript, signedScript))
|
||||
val expected = context.assets.open("linuxfs" + PATH).use { digest(it, MAX_BINARY_BYTES) }
|
||||
Ticket(0, root, configuredRoot, file, expected, SystemClock.elapsedRealtime() + TTL_MS)
|
||||
Ticket(0, root, configuredRoot, file, expected, SystemClock.elapsedRealtime() + TTL_MS, steamGameUrl)
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
@@ -113,11 +123,15 @@ internal object FrameAcquireWorkerProbe {
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
|
||||
internal fun exactGamescopeArgs(argv: List<String>, script: (String) -> Boolean): Boolean {
|
||||
internal fun exactGamescopeArgs(
|
||||
argv: List<String>, steamGameUrl: String? = null, script: (String) -> Boolean,
|
||||
): Boolean {
|
||||
if (argv.firstOrNull() !in listOf("gamescope", PATH)) return false
|
||||
val delimiter = argv.indexOf("--")
|
||||
if (delimiter < 4 || argv.size != delimiter + 3 || argv[delimiter + 2] != "steam" ||
|
||||
!script(argv[delimiter + 1])) return false
|
||||
val tailSize = if (steamGameUrl == null) 3 else 4
|
||||
if (delimiter < 4 || argv.size != delimiter + tailSize || argv[delimiter + 2] != "steam" ||
|
||||
!script(argv[delimiter + 1]) ||
|
||||
(steamGameUrl != null && (!permittedLaunch(steamGameUrl, true) || argv.last() != steamGameUrl))) return false
|
||||
val opts = argv.subList(1, delimiter)
|
||||
if (opts.take(4) != listOf("--backend", "wayland", "--expose-wayland", "-f")) return false
|
||||
val dimensions = setOf("-W", "-H", "-w", "-h")
|
||||
@@ -152,7 +166,7 @@ internal object FrameAcquireWorkerProbe {
|
||||
SystemClock.elapsedRealtime() >= t.expires -> Reason.MATCH_EXPIRED
|
||||
file != PATH -> Reason.MATCH_PATH
|
||||
runCatching { root.canonicalFile }.getOrNull() != t.root -> Reason.MATCH_ROOT
|
||||
!exactGamescopeArgs(argv) { exactSteamScript(it, t.root, t.configuredRoot) } -> Reason.MATCH_ARGV
|
||||
!exactGamescopeArgs(argv, t.steamGameUrl) { exactSteamScript(it, t.root, t.configuredRoot) } -> Reason.MATCH_ARGV
|
||||
else -> null
|
||||
}
|
||||
if (rejection != null) {
|
||||
|
||||
@@ -394,8 +394,10 @@ class SessionService : Service() {
|
||||
SessionState.program = intent?.getStringExtra(EXTRA_PROGRAM)
|
||||
SessionState.programArgs = intent?.getStringArrayExtra(EXTRA_PROGRAM_ARGS)?.toList().orEmpty()
|
||||
SessionState.steamUi = intent?.getStringExtra(EXTRA_STEAM_UI)
|
||||
SessionState.steamUrl = intent?.getStringExtra(EXTRA_STEAM_URL)
|
||||
val steamUrlGameId = SessionState.steamUrl
|
||||
val launchSteamUrl = intent?.getStringExtra(EXTRA_STEAM_URL)
|
||||
val frontendSteamGame = intent?.getBooleanExtra(EXTRA_FRONTEND_STEAM_GAME, false) == true
|
||||
SessionState.steamUrl = launchSteamUrl
|
||||
val steamUrlGameId = launchSteamUrl
|
||||
?.let { url ->
|
||||
when {
|
||||
url.startsWith(GAME_URL_PREFIX) ->
|
||||
@@ -447,7 +449,7 @@ class SessionService : Service() {
|
||||
Thread({
|
||||
OrphanReaper.reap("session starting")
|
||||
ProtonExtras.awaitReplacement(120_000)
|
||||
runSession(gen)
|
||||
runSession(gen, launchSteamUrl, frontendSteamGame)
|
||||
}, "session-start").start()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
@@ -500,7 +502,7 @@ class SessionService : Service() {
|
||||
}
|
||||
|
||||
|
||||
private fun runSession(gen: Int) {
|
||||
private fun runSession(gen: Int, launchSteamUrl: String?, frontendSteamGame: Boolean) {
|
||||
SessionPrefs.ensurePowerVrAutoDriversAfterGpuQuery(this)
|
||||
if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) {
|
||||
com.droiddeck.launcher.gpu.VulkanInfo.query()["api"]?.let { SessionPrefs.setHostVulkanApi(this, it) }
|
||||
@@ -712,7 +714,8 @@ class SessionService : Service() {
|
||||
val fenceWorker = com.droiddeck.launcher.runtime.FrameAcquireWorkerProbe
|
||||
val preparedFence = if (steamHere && !systemVulkan && !VenusComponent.wanted(this) &&
|
||||
SessionPrefs.zeroCopy(this, MODE_STEAM) && SessionPrefs.producerAcquireFences(this) &&
|
||||
nextAgentEnvironment.isSuccess && fenceWorker.validEnvironment(agentEnvironment, customEnvironment)) fenceWorker.prepare(this) else null
|
||||
nextAgentEnvironment.isSuccess && fenceWorker.validEnvironment(agentEnvironment, customEnvironment)
|
||||
) fenceWorker.prepare(this, launchSteamUrl, frontendSteamGame) else null
|
||||
var fenceArmed = false
|
||||
// Under the lock a stop takes its number with: a stop either comes first (and this session
|
||||
// starts no workers) or owns them
|
||||
@@ -751,7 +754,7 @@ class SessionService : Service() {
|
||||
val desktopGuest = ArrayList(guest)
|
||||
guest.add(LinuxRuntime.SESSION_SCRIPT)
|
||||
guest.add(SessionState.mode)
|
||||
if (SessionState.mode == MODE_STEAM) SessionState.steamUrl?.takeIf { it.startsWith("steam://") }?.let {
|
||||
if (SessionState.mode == MODE_STEAM) launchSteamUrl?.takeIf { it.startsWith("steam://") }?.let {
|
||||
guest.add(it)
|
||||
Log.i(TAG, "steam: handing the client $it")
|
||||
}
|
||||
@@ -2769,6 +2772,9 @@ class SessionService : Service() {
|
||||
const val EXTRA_PROGRAM_ARGS = "programArgs"
|
||||
const val EXTRA_STEAM_UI = "steamUi"
|
||||
const val EXTRA_STEAM_URL = "steamUrl"
|
||||
// Set by the first-party Library play action on the private SessionActivity/Service path.
|
||||
// Never copied from an exported intent or Agent command.
|
||||
internal const val EXTRA_FRONTEND_STEAM_GAME = "com.droiddeck.launcher.FRONTEND_STEAM_GAME"
|
||||
const val EXTRA_GAME_ID = "gameId"
|
||||
|
||||
fun start(
|
||||
@@ -2776,6 +2782,7 @@ class SessionService : Service() {
|
||||
steamUi: String? = null, steamUrl: String? = null, programArgs: Array<String>? = null,
|
||||
gameId: String? = null,
|
||||
displayId: Int = Display.DEFAULT_DISPLAY,
|
||||
frontendSteamGame: Boolean = false,
|
||||
) {
|
||||
SteamClientPrefetch.cancel()
|
||||
SessionState.activityDisplayId = displayId
|
||||
@@ -2786,6 +2793,7 @@ class SessionService : Service() {
|
||||
if (programArgs != null) intent.putExtra(EXTRA_PROGRAM_ARGS, programArgs)
|
||||
if (steamUi != null) intent.putExtra(EXTRA_STEAM_UI, steamUi)
|
||||
if (steamUrl != null) intent.putExtra(EXTRA_STEAM_URL, steamUrl)
|
||||
if (frontendSteamGame) intent.putExtra(EXTRA_FRONTEND_STEAM_GAME, true)
|
||||
if (gameId != null) intent.putExtra(EXTRA_GAME_ID, gameId)
|
||||
if (Build.VERSION.SDK_INT >= 26) context.startForegroundService(intent)
|
||||
else context.startService(intent)
|
||||
|
||||
@@ -58,6 +58,35 @@ class FrameAcquireWorkerProbeTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
@Test fun warmSteamAndExactlyExpectedFirstPartyColdLaunchOnly() {
|
||||
val probe = FrameAcquireWorkerProbe
|
||||
val script = "/usr/local/bin/droiddeck-session"
|
||||
val args = listOf("gamescope", "--backend", "wayland", "--expose-wayland", "-f",
|
||||
"-W", "1280", "-H", "720", "-w", "1280", "-h", "720", "--", script, "steam")
|
||||
val url = com.droiddeck.launcher.frontend.GameLaunchLink.steamUrl("3902570")
|
||||
fun valid(actual: List<String>, expected: String?) = probe.exactGamescopeArgs(actual, expected) { it == script }
|
||||
|
||||
assertTrue(probe.permittedLaunch(null, false))
|
||||
assertFalse(probe.permittedLaunch(null, true))
|
||||
assertTrue(probe.permittedLaunch(url, true))
|
||||
assertFalse(probe.permittedLaunch(url, false))
|
||||
assertTrue(valid(args, null))
|
||||
assertTrue(valid(args + url, url))
|
||||
assertFalse(valid(args + url, null))
|
||||
assertFalse(valid(args, url))
|
||||
assertFalse(valid(args + "steam://rungameid/3902571", url))
|
||||
assertFalse(valid(args + listOf(url, ""), url))
|
||||
assertFalse(valid(args + listOf(url, "--version"), url))
|
||||
assertFalse(valid(args + listOf(url, url), url))
|
||||
assertFalse(valid(args.dropLast(2) + listOf("/tmp/droiddeck-session", "steam", url), url))
|
||||
for (bad in listOf("steam://open/library", "steam://run/3902570", "Steam://rungameid/3902570",
|
||||
"steam://rungameid/03902570", "$url/", "$url?x=1", "$url#x", "$url%20",
|
||||
"$url --version", "steam://rungameid/18446744073709551616", "https://example.test/")) {
|
||||
assertFalse(probe.permittedLaunch(bad, true))
|
||||
assertFalse(valid(args + bad, bad))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun selfStatAndFixedBinderReceiptRejectWrongWorkerAndExtraBytes() {
|
||||
val probe = FrameAcquireWorkerProbe
|
||||
val fields = (1..18).joinToString(" ")
|
||||
|
||||
Reference in new issue
Block a user