From ffb2a3d6e6968d476733f176b278658e03c9dae7 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 26 Nov 2026 18:23:25 -0500 Subject: [PATCH] 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. --- .../com/droiddeck/launcher/FrontEndActivity.kt | 6 ++++++ .../launcher/frontend/GameLaunchIntent.kt | 4 ++++ .../launcher/frontend/GameLaunchIntentTest.kt | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 6080477ef3..1912828781 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -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" diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/GameLaunchIntent.kt b/app/src/main/java/com/droiddeck/launcher/frontend/GameLaunchIntent.kt index 3e5d4ae0dd..91349aa6f1 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/GameLaunchIntent.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/GameLaunchIntent.kt @@ -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) diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchIntentTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchIntentTest.kt index 63b6807c0f..8011f23518 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchIntentTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchIntentTest.kt @@ -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)