mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix: preserve input lifecycle and system actions
Keep unused pad rings closed during profile and enable changes. Route Steam menu and VR stick-switch pulses independently of primary bindings, preserving physical holds and cancelling stale releases. Seed replacement routes with retained source state and require held controls to return to neutral. Add nine regressions and document validation: 2,239 JVM tests and the debug APK build pass; device validation remains pending.
This commit is contained in:
1 parent
d202233beb
commit
1dae4bf8ee
9 files changed
+279
-19
No files matched your search
@@ -25,6 +25,21 @@ class InputRouterTest {
|
||||
assertTrue(output.events.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun retainedPadReturnsToNativeFastPathAfterHeldControlsReachNeutral() {
|
||||
val raw = PadState().apply { press(PadState.A, true); leftX = .8f }
|
||||
val source = router.pad(InputRole.PHYSICAL, raw)
|
||||
raw.press(PadState.B, true)
|
||||
val blocked = source.route(raw)
|
||||
assertFalse(blocked.isDown(PadState.A))
|
||||
assertEquals(0f, blocked.leftX)
|
||||
assertTrue(blocked.isDown(PadState.B))
|
||||
raw.clear()
|
||||
source.route(raw)
|
||||
raw.press(PadState.A, true)
|
||||
repeat(1000) { assertSame(raw, source.route(raw)) }
|
||||
assertTrue(output.events.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun localBindingConsumesOnlyItsOwnNativeControlAndReleasesModifiersLast() {
|
||||
router.setProfile(bind(InputControl.A, InputAction.Keys(listOf(29, 30))))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, shadows = [JoyConPadTest.RecordingWriter::class])
|
||||
@@ -16,6 +17,94 @@ class InputSourceOwnershipTest {
|
||||
private fun state() = JoyConPadTest.RecordingWriter.pads[0]!!
|
||||
@After fun close() { bridge.stop(); DeckControls.releaseAll(); DeckControls.setRouter(null) }
|
||||
|
||||
@Test fun profileAndEnableChangesLeaveRingClosedUntilInputArrives() {
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()))
|
||||
bridge.setInputProfile(InputProfile.defaults(InputProfile.DESKTOP))
|
||||
bridge.setInputEnabled(false)
|
||||
bridge.setInputEnabled(true)
|
||||
assertFalse(ReflectionHelpers.getField<Boolean>(bridge, "open"))
|
||||
bridge.applyExternal({ it.press(PadState.X, true) }, true)
|
||||
assertTrue(ReflectionHelpers.getField<Boolean>(bridge, "open"))
|
||||
}
|
||||
|
||||
@Test fun disablingRoutingPublishesReleaseToAnAlreadyOpenRing() {
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()))
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
bridge.setInputEnabled(false)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
bridge.setInputEnabled(true)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun replacingRouterReleasesRetainedPhysicalAndTouchHoldsUntilNeutral() {
|
||||
val before = RecordingOutput()
|
||||
val after = RecordingOutput()
|
||||
val profile = InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Keys(listOf(29)))
|
||||
.withBinding(InputRole.SECONDARY, InputControl.B, InputAction.Keys(listOf(29)))
|
||||
bridge.setInputRouter(InputRouter(before).also { it.setProfile(profile) })
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
val touch = Any()
|
||||
bridge.applyTouch(touch, InputRole.SECONDARY) { it.press(PadState.B, true) }
|
||||
bridge.setInputRouter(InputRouter(after).also { it.setProfile(profile) })
|
||||
bridge.applyExternal({ it.press(PadState.X, true) }, true)
|
||||
assertEquals(listOf("key 29 true", "key 29 false"), before.events)
|
||||
assertTrue(after.events.isEmpty())
|
||||
bridge.applyExternal({ it.press(PadState.A, false) }, true)
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
assertEquals(listOf("key 29 true"), after.events)
|
||||
bridge.applyExternal({ it.press(PadState.A, false) }, true)
|
||||
assertEquals(listOf("key 29 true", "key 29 false"), after.events)
|
||||
bridge.applyTouch(touch, InputRole.SECONDARY) { it.press(PadState.B, false) }
|
||||
bridge.applyTouch(touch, InputRole.SECONDARY) { it.press(PadState.B, true) }
|
||||
assertEquals("key 29 true", after.events.last())
|
||||
}
|
||||
|
||||
@Test fun replacingRouterReleasesRetainedNativeButtonsAndStick() {
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()))
|
||||
bridge.applyExternal({ it.press(PadState.A, true); it.leftX = .8f }, true)
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()))
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertEquals(0f, state().leftX)
|
||||
bridge.applyExternal({ it.press(PadState.B, true) }, true)
|
||||
assertTrue(state().isDown(PadState.B))
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertEquals(0f, state().leftX)
|
||||
bridge.applyExternal({ it.press(PadState.A, false); it.leftX = 0f }, true)
|
||||
bridge.applyExternal({ it.press(PadState.A, true); it.leftX = .8f }, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
assertEquals(.8f, state().leftX)
|
||||
}
|
||||
|
||||
@Test fun replacingDeckRouterBlocksExistingGripAndContactUntilRelease() {
|
||||
DeckControls.setRouter(InputRouter(RecordingOutput()))
|
||||
val surface = DeckControls.source(InputRole.SECONDARY)
|
||||
try {
|
||||
surface.setGrip(DeckControls.L4, true)
|
||||
surface.setPad(false, true, .3f, .4f)
|
||||
DeckControls.setRouter(InputRouter(RecordingOutput()))
|
||||
assertEquals(0, JoyConPadTest.RecordingWriter.grips)
|
||||
surface.setPad(false, true, .5f, .6f)
|
||||
assertEquals(0, JoyConPadTest.RecordingWriter.grips)
|
||||
surface.setGrip(DeckControls.L4, false)
|
||||
surface.setPad(false, false)
|
||||
surface.setGrip(DeckControls.L4, true)
|
||||
surface.setPad(false, true, .2f, .3f)
|
||||
assertEquals(DeckControls.L4 or 16, JoyConPadTest.RecordingWriter.grips)
|
||||
} finally { surface.close() }
|
||||
}
|
||||
|
||||
private class RecordingOutput : InputOutput {
|
||||
val events = mutableListOf<String>()
|
||||
override fun key(code: Int, down: Boolean) { events += "key $code $down" }
|
||||
override fun button(code: Int, down: Boolean) { events += "button $code $down" }
|
||||
override fun pointer(dx: Float, dy: Float) { events += "pointer" }
|
||||
override fun scroll(steps: Int) { events += "scroll" }
|
||||
override fun command(command: InputCommand) { events += command.name }
|
||||
override fun requestMotion() { events += "motion" }
|
||||
}
|
||||
|
||||
@Test fun removingLastTouchSurfaceReleasesLegacyMouseRoute() {
|
||||
val routed = PadState()
|
||||
bridge.setTouchRoute(object : PadBridge.TouchRoute {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import java.io.File
|
||||
import java.time.Duration
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, shadows = [JoyConPadTest.RecordingWriter::class])
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class SessionSystemInputTest {
|
||||
private val bridge = PadBridge(File(RuntimeEnvironment.getApplication().cacheDir, "system-input"))
|
||||
private val activity = Robolectric.buildActivity(SessionActivity::class.java).get().also {
|
||||
ReflectionHelpers.setField(it, "padBridge", bridge)
|
||||
}
|
||||
private val output = RecordingOutput()
|
||||
private val router = InputRouter(output).also {
|
||||
bridge.setInputRouter(it)
|
||||
bridge.setInputProfile(InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PRIMARY, InputControl.GUIDE, InputAction.Disabled)
|
||||
.withBinding(InputRole.PRIMARY, InputControl.L3, InputAction.Keys(listOf(29)))
|
||||
.withBinding(InputRole.PRIMARY, InputControl.R3, InputAction.Command(InputCommand.MENU)))
|
||||
}
|
||||
|
||||
@After fun close() { bridge.stop(); advance(500) }
|
||||
|
||||
@Test fun steamMenuBypassesPrimaryBindingsAndDisabledRouting() {
|
||||
bridge.setInputEnabled(false)
|
||||
invoke("sendSteamGuide")
|
||||
assertTrue(state().isDown(PadState.GUIDE))
|
||||
advance(90)
|
||||
assertFalse(state().isDown(PadState.GUIDE))
|
||||
assertTrue(output.events.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun vrStickSwitchBypassesPrimaryBindingsAndPreservesPhysicalHold() {
|
||||
bridge.applyExternal({ it.press(PadState.L3, true) }, true)
|
||||
invoke("switchVrSticks")
|
||||
assertTrue(state().isDown(PadState.L3))
|
||||
assertTrue(state().isDown(PadState.R3))
|
||||
advance(120)
|
||||
assertTrue(state().isDown(PadState.L3))
|
||||
assertFalse(state().isDown(PadState.R3))
|
||||
assertTrue(output.events.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun releasingSystemActionsCancelsOldVrReleaseWithoutEndingNewTap() {
|
||||
invoke("switchVrSticks")
|
||||
advance(60)
|
||||
bridge.releaseAll()
|
||||
assertFalse(state().isDown(PadState.L3))
|
||||
assertFalse(state().isDown(PadState.R3))
|
||||
invoke("switchVrSticks")
|
||||
advance(60)
|
||||
assertTrue(state().isDown(PadState.L3))
|
||||
assertTrue(state().isDown(PadState.R3))
|
||||
advance(60)
|
||||
assertFalse(state().isDown(PadState.L3))
|
||||
assertFalse(state().isDown(PadState.R3))
|
||||
}
|
||||
|
||||
private fun state() = JoyConPadTest.RecordingWriter.pads[0]!!
|
||||
private fun invoke(name: String) = ReflectionHelpers.callInstanceMethod<Unit>(activity, name)
|
||||
private fun advance(ms: Long) {
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms))
|
||||
shadowOf(ReflectionHelpers.getStaticField<Handler>(PadBridge::class.java, "chordHandler").looper).idle()
|
||||
}
|
||||
|
||||
private class RecordingOutput : InputOutput {
|
||||
val events = mutableListOf<String>()
|
||||
override fun key(code: Int, down: Boolean) { events += "key $code $down" }
|
||||
override fun button(code: Int, down: Boolean) { events += "button $code $down" }
|
||||
override fun pointer(dx: Float, dy: Float) { events += "pointer" }
|
||||
override fun scroll(steps: Int) { events += "scroll" }
|
||||
override fun command(command: InputCommand) { events += command.name }
|
||||
override fun requestMotion() { events += "motion" }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user