From 8290837584124ffbec6529f70e86458a7d967116 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 19:44:00 -0500 Subject: [PATCH] Keep long direct-run controller profile keys bounded --- .../com/droiddeck/launcher/SessionActivity.kt | 3 ++- .../droiddeck/launcher/input/InputLibrary.kt | 12 +++++++++++- .../launcher/input/InputLibraryTest.kt | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index e324b5c669..61c633d16f 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -87,6 +87,7 @@ import com.droiddeck.launcher.input.InputProfiles import com.droiddeck.launcher.input.InputProfile import com.droiddeck.launcher.input.InputAction import com.droiddeck.launcher.input.InputRole +import com.droiddeck.launcher.input.boundedInputGameKey import com.droiddeck.launcher.input.InputControl import com.droiddeck.launcher.input.InputMotion import com.droiddeck.launcher.input.HeldInput @@ -4808,7 +4809,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (SessionState.mode == SessionService.MODE_RUN) SessionState.gameId?.takeIf { it.isNotBlank() }?.let { "game:$it" } ?: gestureGame else gestureGame - private fun inputGameKey(): String? = bottomGameKey() + private fun inputGameKey(): String? = bottomGameKey()?.let(::boundedInputGameKey) /** Opens the effective controls. Fork a per-game part only when the editor saves an actual change. */ private fun openInputEditor(role: InputRole) { diff --git a/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt b/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt index 04f7a37546..3947fac805 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt @@ -1,7 +1,17 @@ package com.droiddeck.launcher.input +import java.security.MessageDigest import java.util.UUID +private const val MAX_INPUT_GAME_KEY_LENGTH = 128 + +/** Keep existing keys intact; long ad-hoc launch paths have no stable short game ID. */ +internal fun boundedInputGameKey(key: String): String { + if (key.length <= MAX_INPUT_GAME_KEY_LENGTH || !key.startsWith("program:")) return key + val digest = MessageDigest.getInstance("SHA-256").digest(key.toByteArray(Charsets.UTF_8)) + return "program-sha256:" + digest.joinToString("") { "%02x".format(it.toInt() and 0xff) } +} + enum class InputLayoutTemplate { CUSTOM, OVERLAY, DECK, TRACKPAD } enum class InputLayoutScreen { MAIN, SECONDARY, BOTH; @@ -384,7 +394,7 @@ data class InputLibrary( } require(games.size <= 512) for ((key, game) in games) { - require(key.isNotBlank() && key.length <= 128) + require(key.isNotBlank() && key.length <= MAX_INPUT_GAME_KEY_LENGTH) inputName(game.name) require(game.profile == null || profiles.any { it.id == game.profile }) require(game.profile != null || game.parts.isNotEmpty()) diff --git a/app/src/test/java/com/droiddeck/launcher/input/InputLibraryTest.kt b/app/src/test/java/com/droiddeck/launcher/input/InputLibraryTest.kt index f9019ab2a6..eaf36324f2 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/InputLibraryTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/InputLibraryTest.kt @@ -22,6 +22,25 @@ class InputLibraryTest { for (name in listOf("input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit() } + @Test fun longDirectRunPathsCanSaveDistinctGameProfiles() { + val oldKey = "program:" + "x".repeat(120) + val common = "program:/games/" + "é".repeat(130) + val first = boundedInputGameKey("$common/one.exe") + val second = boundedInputGameKey("$common/two.exe") + assertEquals(oldKey, boundedInputGameKey(oldKey)) + assertEquals("game:42", boundedInputGameKey("game:42")) + assertEquals("42", boundedInputGameKey("42")) + assertEquals(first, boundedInputGameKey("$common/one.exe")) + assertTrue(first.length <= 128) + assertNotEquals(first, second) + val library = InputLibraries.read(context) + .withGameProfile(first, "First", InputProfile.GAME) + .withGameProfile(second, "Second", InputProfile.DESKTOP).validate() + assertEquals(InputProfile.GAME, library.activeId(false, first)) + assertEquals(InputProfile.DESKTOP, library.activeId(false, second)) + assertTrue(library.games.keys.containsAll(listOf(first, second))) + } + @Test fun freshLibraryHasTheMainGamepadAndTheStockLowerScreenLayouts() { val library = InputLibraries.read(context) assertEquals(listOf("game", "desktop"), library.profiles.map { it.id })