mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Preserve second-screen choices across partial selections and migration retries
Track explicit whole-profile choices, including Auto, separately from inherited profiles so physical and main-screen overrides do not suppress legacy panel migration. Persist this distinction in library version 8 and read older selection records compatibly. Keep saved Deck panels during unavailable-controller fallbacks and retain legacy preferences when migration fails. Add regressions for all three review findings, explicit Auto selection and older saved libraries. Validation: all 992 input/UI tests passed.
This commit is contained in:
1 parent
281c2aea1b
commit
aff9738748
5 files changed
+110
-13
No files matched your search
@@ -284,6 +284,36 @@ class InputLibraryTest {
|
||||
assertEquals(original.compileActive(true), restored.compileActive(true))
|
||||
}
|
||||
|
||||
@Test fun explicitAutoSelectionStaysDistinctFromAnInheritedProfileAfterSaving() {
|
||||
val original = InputLibraries.read(context)
|
||||
val binding = original.profile("game").binding(InputRole.PHYSICAL)
|
||||
val inherited = original.selectPart(false, InputRole.PHYSICAL, binding)
|
||||
val explicit = original.selectProfile(false, InputProfiles.AUTO).selectPart(false, InputRole.PHYSICAL, binding)
|
||||
assertFalse(InputLibraries.decode(InputLibraries.encode(inherited))!!.selection(false).profileSelected)
|
||||
assertTrue(InputLibraries.decode(InputLibraries.encode(explicit))!!.selection(false).profileSelected)
|
||||
assertEquals(inherited.compileActive(false), explicit.compileActive(false))
|
||||
}
|
||||
|
||||
@Test fun versionSevenSelectionsRetainKnownProfileAndPartChoices() {
|
||||
val original = InputLibraries.read(context)
|
||||
val binding = original.profile("game").binding(InputRole.PHYSICAL)
|
||||
val choices = listOf(
|
||||
original.selectPart(false, InputRole.PHYSICAL, binding) to false,
|
||||
original.selectProfile(false, InputProfiles.AUTO) to true,
|
||||
original.selectProfile(false, "game").selectPart(false, InputRole.PHYSICAL, binding) to true,
|
||||
original.selectPart(false, InputRole.SECONDARY, InputStockLayouts.TRACKPAD) to false,
|
||||
)
|
||||
for ((library, selected) in choices) {
|
||||
val old = org.json.JSONObject(InputLibraries.encode(library)).put("version", 7)
|
||||
old.getJSONObject("selections").getJSONObject("game").remove("profileSelected")
|
||||
prefs.edit().putString("library", old.toString()).commit()
|
||||
val restored = InputLibraries.read(context)
|
||||
assertEquals(selected, restored.selection(false).profileSelected)
|
||||
assertEquals(library, restored)
|
||||
assertEquals(restored, InputLibraries.read(context))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun savedQuickCombinationOwnsIndependentCopiesOfAllThreeParts() {
|
||||
val original = InputLibraries.read(context)
|
||||
val mixed = original.selectPart(true, InputRole.SECONDARY, InputStockLayouts.TRACKPAD)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.view.Display
|
||||
import androidx.compose.runtime.MutableState
|
||||
@@ -7,6 +8,7 @@ import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
@@ -88,6 +90,62 @@ class SecondScreenProfileMigrationTest {
|
||||
assertEquals(SecondScreenMode.CUSTOM_CONTROLS.id, SessionPrefs.secondScreenPanel(activity))
|
||||
}
|
||||
|
||||
@Test fun unrelatedPartSelectionsDoNotSkipTheSavedPanelMigration() {
|
||||
for (desktop in listOf(false, true)) for (role in listOf(InputRole.PHYSICAL, InputRole.PRIMARY)) {
|
||||
customLibrary(desktop)
|
||||
val original = InputLibraries.update(activity) { it.selectPart(desktop, role, it.profile("game").binding(role)) }
|
||||
SessionPrefs.setSecondScreenPanel(activity, SecondScreenMode.KEYBOARD_TRACKPAD.id)
|
||||
open(SecondScreenMode.KEYBOARD_TRACKPAD.id, deckPad = true)
|
||||
assertEquals(original.selectPart(desktop, InputRole.SECONDARY, InputStockLayouts.TRACKPAD), InputLibraries.read(activity))
|
||||
assertEquals(SecondScreenMode.CUSTOM_CONTROLS.id, SessionPrefs.secondScreenPanel(activity))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun explicitProfilesIncludingAutoKeepTheirSecondaryLayoutAfterOtherPartChanges() {
|
||||
for (desktop in listOf(false, true)) for (profile in listOf(InputProfiles.AUTO, InputProfile.GAME, InputProfile.DESKTOP)) {
|
||||
for (role in listOf(null, InputRole.PHYSICAL, InputRole.PRIMARY)) {
|
||||
customLibrary(desktop)
|
||||
val original = InputLibraries.update(activity) { library ->
|
||||
val selected = library.selectProfile(desktop, profile)
|
||||
if (role == null) selected else selected.selectPart(desktop, role, selected.profile("game").binding(role))
|
||||
}
|
||||
SessionPrefs.setSecondScreenPanel(activity, SecondScreenMode.DECK_CONTROLS.id)
|
||||
open(SecondScreenMode.DECK_CONTROLS.id, deckPad = true)
|
||||
assertEquals(original, InputLibraries.read(activity))
|
||||
assertEquals(SecondScreenMode.CUSTOM_CONTROLS.id, SessionPrefs.secondScreenPanel(activity))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun unavailableDeckPanelKeepsItsSavedChoiceUntilItCanMigrate() {
|
||||
for (desktop in listOf(false, true)) {
|
||||
val original = customLibrary(desktop)
|
||||
SessionPrefs.setSecondScreenPanel(activity, SecondScreenMode.DECK_CONTROLS.id)
|
||||
open(SecondScreenMode.DECK_CONTROLS.id, deckPad = false)
|
||||
assertEquals(original, InputLibraries.read(activity))
|
||||
assertEquals(SecondScreenMode.DECK_CONTROLS.id, SessionPrefs.secondScreenPanel(activity))
|
||||
open(SessionPrefs.secondScreenPanel(activity), deckPad = true)
|
||||
assertEquals(original.selectPart(desktop, InputRole.SECONDARY, InputStockLayouts.DECK), InputLibraries.read(activity))
|
||||
assertEquals(SecondScreenMode.CUSTOM_CONTROLS.id, SessionPrefs.secondScreenPanel(activity))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun failedMigrationKeepsTheSavedPanelAndCanBeRetried() {
|
||||
val original = customLibrary(desktop = false)
|
||||
val prefs = activity.getSharedPreferences("input-profiles", Context.MODE_PRIVATE)
|
||||
val valid = prefs.getString("library", null)!!
|
||||
val unsupported = JSONObject(valid).put("version", 999).toString()
|
||||
prefs.edit().putString("library", unsupported).commit()
|
||||
SessionPrefs.setSecondScreenPanel(activity, SecondScreenMode.KEYBOARD_TRACKPAD.id)
|
||||
open(SecondScreenMode.KEYBOARD_TRACKPAD.id, deckPad = true)
|
||||
assertEquals(unsupported, prefs.getString("library", null))
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD.id, SessionPrefs.secondScreenPanel(activity))
|
||||
prefs.edit().putString("library", valid).commit()
|
||||
open(SessionPrefs.secondScreenPanel(activity), deckPad = true)
|
||||
assertEquals(original.selectPart(false, InputRole.SECONDARY, InputStockLayouts.TRACKPAD), InputLibraries.read(activity))
|
||||
assertEquals(SecondScreenMode.CUSTOM_CONTROLS.id, SessionPrefs.secondScreenPanel(activity))
|
||||
}
|
||||
|
||||
private fun customLibrary(desktop: Boolean): InputLibrary {
|
||||
SessionState.mode = if (desktop) SessionService.MODE_DESKTOP else SessionService.MODE_STEAM
|
||||
return InputLibraries.update(activity) { library ->
|
||||
|
||||
Reference in new issue
Block a user