mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Keep long direct-run controller profile keys bounded
This commit is contained in:
1 parent
2469653f86
commit
8290837584
3 files changed
+32
-2
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in new issue
Block a user