Compare commits

...
Author SHA1 Message Date
MaxsTechReview 6877a5e8e6 perf(session): check the known game process first in the game exit watcher (#3306)
Check the known game process first when watching for the game to exit
2026-11-26 18:59:27 -05:00
MaxsTechReview 25923966eb perf(hud): read thermal zone types once instead of on every refresh (#3304)
* Read thermal zone types once for the HUD

Every HUD refresh listed /sys/class/thermal and opened every zone's type file three or four times (CPU temperature, GPU temperature and the replaced-zone check). Zone types do not change while the device runs, so the sorted map is read once and reused.

* Cache thermal zone types only after a scan with no read failures
2026-11-26 18:44:24 -05:00
MaxsTechReview ffb2a3d6e6 fix(frontend): a restored front end no longer relaunches the game from its old link (#3295)
* fix(frontend): a restored front end no longer relaunches the game from its old link

When the system kills the app while a game started from a droiddeck:// link
is running, reopening the task restores the front end with that same link
and starts the game again. The link is now dropped when a new process
restores the activity or Recents reopens it, so only a fresh link launches.

* fix(frontend): judge every restored front end by the process that saved it

* Keep restored settings links working

Only game links are dropped when a restored front end replays its intent; droiddeck://settings links still open their page.
2026-11-26 18:23:25 -05:00
7 changed files with 68 additions and 13 deletions

No files matched your search

@@ -1349,6 +1349,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
val shortcutsFilter = android.content.IntentFilter(SteamIntegration.SHORTCUTS_STATUS)
if (android.os.Build.VERSION.SDK_INT >= 33) registerReceiver(shortcutsInstallStatus, shortcutsFilter, RECEIVER_NOT_EXPORTED)
else registerReceiver(shortcutsInstallStatus, shortcutsFilter)
if (GameLaunchIntent.accepts(intent.action) &&
GameLaunchIntent.replayed(intent, savedInstanceState != null, savedInstanceState?.getString(STATE_PROCESS), PROCESS))
clearGameLinkIntent(intent)
readGameIntent(intent)
// A Lab build is usually the agent's work, so the app comes back where the agent is.
if (savedInstanceState == null && navRequest == null && com.droiddeck.launcher.lab.LabOverlay.promoted && com.droiddeck.launcher.agent.AgentTab.visible) navRequest = "agent"
@@ -2312,6 +2315,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
}
private fun saveLauncherState(outState: Bundle) {
outState.putString(STATE_PROCESS, PROCESS)
outState.putBoolean(STATE_HOME_CHOICE_OPEN, homeChoiceOpen)
outState.putBoolean(STATE_GAME_SPACE_OFFERED, gameSpaceOffered)
pendingSessionLogExport?.let { outState.putString(KEY_PENDING_SESSION_LOG_EXPORT, it.absolutePath) }
@@ -3684,6 +3688,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
}
companion object {
private val PROCESS = java.util.UUID.randomUUID().toString()
private const val STATE_PROCESS = "process"
private const val REQUEST_NOTIFICATIONS = 7103
private const val EXTRA_RESTARTED = "com.droiddeck.launcher.extra.RESTARTED"
private const val STATE_HOME_CHOICE_OPEN = "home_choice_open"
@@ -11,6 +11,10 @@ object GameLaunchIntent {
fun accepts(action: String?): Boolean = action == Intent.ACTION_VIEW || action == ACTION || action == GAMENATIVE_ACTION
fun replayed(intent: Intent, restored: Boolean, savedProcess: String?, process: String): Boolean =
!(intent.data?.scheme == "droiddeck" && intent.data?.host == "settings") &&
(intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0 || restored && savedProcess != process)
fun read(context: Context, intent: Intent): GameRequest? = when (intent.action) {
Intent.ACTION_VIEW -> GameFiles.readIntent(context, intent)
ACTION, GAMENATIVE_ACTION -> readExtras(intent)
@@ -512,7 +512,7 @@ public final class LinuxRuntime {
public static List<File> cpuTempZones() {
java.util.Map<String, String> replaced = replacedZoneTypes();
List<File> zones = new ArrayList<>();
for (java.util.Map.Entry<String, File> zone : new java.util.TreeMap<>(thermalZones()).entrySet()) {
for (java.util.Map.Entry<String, File> zone : thermalZones().entrySet()) {
String type = zone.getKey();
if (type.contains("cpu") && !type.contains("gpu") && !replaced.containsKey(zone.getValue().getName())) {
zones.add(zone.getValue());
@@ -555,23 +555,31 @@ public final class LinuxRuntime {
private static String thermalZone(String sensor) {
java.util.Map<String, File> zones = thermalZones();
File zone = zones.get(sensor);
for (java.util.Map.Entry<String, File> e : new java.util.TreeMap<>(zones).entrySet()) {
for (java.util.Map.Entry<String, File> e : zones.entrySet()) {
if (zone == null && e.getKey().contains(sensor)) zone = e.getValue();
}
return zone != null ? new File(zone, "temp").getPath() : null;
}
private static java.util.Map<String, File> thermalZones() {
private static volatile java.util.SortedMap<String, File> thermalZoneTypes;
private static java.util.SortedMap<String, File> thermalZones() {
java.util.SortedMap<String, File> known = thermalZoneTypes;
if (known != null) return known;
java.util.Map<String, File> byType = new java.util.HashMap<>();
File[] zones = new File("/sys/class/thermal").listFiles((dir, n) -> n.startsWith("thermal_zone"));
if (zones == null) return byType;
if (zones == null) return java.util.Collections.emptySortedMap();
boolean complete = true;
for (File zone : zones) {
try (java.io.BufferedReader r = new java.io.BufferedReader(new java.io.FileReader(new File(zone, "type")))) {
byType.putIfAbsent(String.valueOf(r.readLine()).trim().toLowerCase(java.util.Locale.ROOT), zone);
} catch (IOException ignored) {
} catch (IOException e) {
complete = false;
}
}
return byType;
java.util.SortedMap<String, File> sorted = java.util.Collections.unmodifiableSortedMap(new java.util.TreeMap<>(byType));
if (complete && !sorted.isEmpty()) thermalZoneTypes = sorted;
return sorted;
}
private static void bindSystemFonts(List<String> cmd, File root) {
@@ -1727,6 +1727,7 @@ class SessionService : Service() {
var startupWasSuspended = false
var seen = false
var goneSince = 0L
var gamePid: String? = null
while (token == gameExitWatchToken && gen == sessionGen && SessionState.running && !SessionState.stopRequested) {
val now = android.os.SystemClock.elapsedRealtime()
val startupSuspended = SessionState.suspended || SessionState.suspending || SessionState.phase != SessionPhase.READY
@@ -1742,7 +1743,8 @@ class SessionService : Service() {
lastStartupCheck = now
}
}
if (steamGameRunning(gameId)) {
gamePid = SteamGameProcess.runningPid(gameId, gamePid)
if (gamePid != null) {
if (!seen) {
Log.i(TAG, "game $gameId started; tracking its exit")
mainHandler.post {
@@ -55,12 +55,15 @@ object SteamGameProcess {
return false
}
fun running(gameId: String, proc: File = File("/proc")): Boolean =
proc.listFiles()?.any { p ->
p.name.all(Char::isDigit) &&
runCatching { File(p, "cmdline").readBytes() }
.getOrNull()?.let { matches(it, gameId) } == true
} == true
fun running(gameId: String, proc: File = File("/proc")): Boolean = runningPid(gameId, null, proc) != null
fun runningPid(gameId: String, known: String?, proc: File = File("/proc")): String? {
if (known != null && runs(File(proc, known), gameId)) return known
return proc.listFiles()?.firstOrNull { p -> p.name.all(Char::isDigit) && runs(p, gameId) }?.name
}
private fun runs(process: File, gameId: String): Boolean =
runCatching { File(process, "cmdline").readBytes() }.getOrNull()?.let { matches(it, gameId) } == true
// A front end that resumes a player by launching the same game again would otherwise have Steam
// start it a second time, which Steam answers with "Game already running".
@@ -20,6 +20,22 @@ class GameLaunchIntentTest {
}
}
@Test fun aLinkIsReplayedOnlyWhenANewProcessRestoresItOrRecentsReopensIt() {
val link = Intent(Intent.ACTION_VIEW)
assertFalse(GameLaunchIntent.replayed(link, restored = false, savedProcess = null, process = "b"))
assertFalse(GameLaunchIntent.replayed(link, restored = true, savedProcess = "b", process = "b"))
assertTrue(GameLaunchIntent.replayed(link, restored = true, savedProcess = "a", process = "b"))
assertTrue(GameLaunchIntent.replayed(link, restored = true, savedProcess = null, process = "b"))
val fromRecents = Intent(link).addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
assertTrue(GameLaunchIntent.replayed(fromRecents, restored = false, savedProcess = null, process = "b"))
assertTrue(GameLaunchIntent.replayed(fromRecents, restored = true, savedProcess = "b", process = "b"))
val settings = Intent(Intent.ACTION_VIEW, android.net.Uri.parse("droiddeck://settings/storage"))
.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
assertFalse(GameLaunchIntent.replayed(settings, restored = true, savedProcess = "a", process = "b"))
assertTrue(GameLaunchIntent.replayed(Intent(Intent.ACTION_VIEW, android.net.Uri.parse("droiddeck://game/620")),
restored = true, savedProcess = "a", process = "b"))
}
@Test fun longAndStringIdsPreserveUnsignedShortcutIds() {
listOf("2147483648", "18446744073709551615").forEach { id ->
assertEquals(id, GameLaunchIntent.readExtras(Intent(GameLaunchIntent.ACTION).putExtra("app_id", id))?.id)
@@ -1,6 +1,8 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
@@ -89,6 +91,20 @@ class SteamGameProcessTest {
assertTrue(SteamGameProcess.running("351710", proc))
}
@Test fun aKnownGameProcessIsCheckedBeforeEveryOtherProcess() {
val proc = tmp.newFolder("proc")
fun process(pid: String, vararg args: String) = File(proc, pid).apply { mkdirs() }.resolve("cmdline").writeBytes(cmdline(*args))
process("100", "reaper", "SteamLaunch", "AppId=1")
process("200", "reaper", "SteamLaunch", "AppId=1")
assertEquals("200", SteamGameProcess.runningPid("1", "200", proc))
File(proc, "200/cmdline").writeBytes(cmdline("bash"))
assertEquals("100", SteamGameProcess.runningPid("1", "200", proc))
assertEquals("100", SteamGameProcess.runningPid("1", "999", proc))
File(proc, "100").deleteRecursively()
assertNull(SteamGameProcess.runningPid("1", "100", proc))
assertNull(SteamGameProcess.runningPid("2", null, proc))
}
@Test fun onlyTheRunningCurrentGameCountsAsAlreadyRunning() {
val proc = tmp.newFolder("proc-relaunch")
File(proc, "200").apply { mkdirs() }.resolve("cmdline")