fix: keep select mapping and panel input ownership consistent

Keep Select-as-Steam in the existing one-time profile migration and remove the obsolete bridge flag. Raw SELECT state stays stable across router attachment changes, while explicit native, disabled and local profile bindings remain authoritative.

Let the panel close its shared DeckControls source. Detached sticks, D-pads and face buttons release only their own controls, preserving other trackpad contacts and clicks.

Add seven regressions. All 2,246 JVM tests pass; the debug APK build, session assets and runtime inputs validate. Thor validation remains pending.
This commit is contained in:
Delete228 committed 2026-10-24 02:52:09 +03:00
1 parent 1dae4bf8ee
commit 884671a065
7 files changed
+250 -15

No files matched your search

@@ -0,0 +1,110 @@
package com.droiddeck.launcher.input
import android.hardware.input.InputManager
import android.view.InputDevice
import android.view.KeyEvent
import java.io.File
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import org.robolectric.shadows.InputDeviceBuilder
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], manifest = Config.NONE, shadows = [JoyConPadTest.RecordingWriter::class,
PadBridgeRoutingTest.RegisteredKeyEvent::class])
class SelectProfileRoutingTest {
private val context get() = RuntimeEnvironment.getApplication()
private val bridge = PadBridge(File(context.cacheDir, "select-profile"))
private val events = mutableListOf<String>()
private val output = object : InputOutput {
override fun key(code: Int, down: Boolean) { events += "key $code $down" }
override fun button(code: Int, down: Boolean) = Unit
override fun pointer(dx: Float, dy: Float) = Unit
override fun scroll(steps: Int) = Unit
override fun command(command: InputCommand) { events += command.name }
override fun requestMotion() = Unit
}
private val device = InputDeviceBuilder.newBuilder().setId(42).setName("Select test pad")
.setDescriptor("select-test").setSources(InputDevice.SOURCE_GAMEPAD).build()
@Before fun setUp() {
context.getSharedPreferences("input-profiles", 0).edit().clear().commit()
context.getSharedPreferences("controller", 0).edit().clear().commit()
ControllerPrefs.setSelectSteam(context, true)
shadowOf(context.getSystemService(InputManager::class.java)).addInputDevice(device)
bridge.setInputRouter(InputRouter(output))
bridge.setInputProfile(InputProfiles.active(context, desktop = false))
}
@After fun close() { bridge.stop() }
@Test fun migratedSteamSelectReachesGuideAndReleasesWithoutReleasingPhysicalGuide() {
key(KeyEvent.KEYCODE_BUTTON_SELECT, true)
assertTrue(state().isDown(PadState.GUIDE))
assertFalse(state().isDown(PadState.SELECT))
key(KeyEvent.KEYCODE_BUTTON_MODE, true)
key(KeyEvent.KEYCODE_BUTTON_SELECT, false)
assertTrue(state().isDown(PadState.GUIDE))
key(KeyEvent.KEYCODE_BUTTON_MODE, false)
assertFalse(state().isDown(PadState.GUIDE))
}
@Test fun profileResetAndExplicitNativeBindingOverrideTheMigratedSetting() {
val migrated = InputProfiles.active(context, desktop = false)
InputProfiles.save(context, migrated.withBinding(InputRole.PHYSICAL, InputControl.SELECT, InputAction.Native()))
bridge.setInputProfile(InputProfiles.active(context, desktop = false))
assertNativeSelect()
InputProfiles.reset(context, InputProfile.GAME)
bridge.setInputProfile(InputProfiles.active(context, desktop = false))
assertNativeSelect()
assertTrue(ControllerPrefs.read(context).selectSteam)
}
@Test fun disabledAndLocalSelectBindingsDoNotLeakGuide() {
for (action in listOf(InputAction.Disabled, InputAction.Keys(listOf(28)), InputAction.Command(InputCommand.KEYBOARD))) {
bridge.setInputProfile(InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.PHYSICAL, InputControl.SELECT, action))
key(KeyEvent.KEYCODE_BUTTON_SELECT, true)
assertFalse(state().isDown(PadState.GUIDE))
assertFalse(state().isDown(PadState.SELECT))
key(KeyEvent.KEYCODE_BUTTON_SELECT, false)
}
assertEquals(listOf("key 28 true", "key 28 false", "KEYBOARD"), events)
}
@Test fun replacingOrRemovingRouterWhileSelectIsHeldNeverLeavesGuideStuck() {
key(KeyEvent.KEYCODE_BUTTON_SELECT, true)
bridge.setInputRouter(null)
assertFalse(state().isDown(PadState.GUIDE))
key(KeyEvent.KEYCODE_BUTTON_SELECT, false)
assertFalse(state().isDown(PadState.SELECT))
key(KeyEvent.KEYCODE_BUTTON_SELECT, true)
bridge.setInputRouter(InputRouter(output).also { it.setProfile(InputProfiles.active(context, desktop = false)) })
assertFalse(state().isDown(PadState.GUIDE))
key(KeyEvent.KEYCODE_BUTTON_SELECT, false)
assertFalse(state().isDown(PadState.GUIDE))
key(KeyEvent.KEYCODE_BUTTON_SELECT, true)
assertTrue(state().isDown(PadState.GUIDE))
key(KeyEvent.KEYCODE_BUTTON_SELECT, false)
assertFalse(state().isDown(PadState.GUIDE))
}
private fun assertNativeSelect() {
key(KeyEvent.KEYCODE_BUTTON_SELECT, true)
assertTrue(state().isDown(PadState.SELECT))
assertFalse(state().isDown(PadState.GUIDE))
key(KeyEvent.KEYCODE_BUTTON_SELECT, false)
}
private fun key(code: Int, down: Boolean) {
assertTrue(bridge.onKeyEvent(KeyEvent(0, 0, if (down) KeyEvent.ACTION_DOWN else KeyEvent.ACTION_UP,
code, 0, 0, device.id, 0, 0, InputDevice.SOURCE_GAMEPAD)))
}
private fun state() = JoyConPadTest.RecordingWriter.pads[0]!!
}
@@ -0,0 +1,110 @@
package com.droiddeck.launcher.ui
import android.app.Activity
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import com.droiddeck.launcher.R
import com.droiddeck.launcher.input.DeckControls
import com.droiddeck.launcher.input.JoyConPadTest
import com.droiddeck.launcher.input.PadBridge
import com.droiddeck.launcher.input.PadState
import com.droiddeck.launcher.session.SessionPrefs
import java.io.File
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], shadows = [JoyConPadTest.RecordingWriter::class])
class DeckControlsPanelOwnershipTest {
private val controller = Robolectric.buildActivity(Activity::class.java).setup()
private val activity = controller.get()
private val root = FrameLayout(activity)
private val bridge = PadBridge(File(activity.cacheDir, "panel-ownership"))
private lateinit var panel: DeckControlsPanel
@Before fun setUp() {
DeckControls.releaseAll()
SessionPrefs.setGamepadSurface(activity, false, SessionPrefs.SURFACE_STICK)
SessionPrefs.setGamepadSurface(activity, true, SessionPrefs.SURFACE_TRACKPAD)
activity.setContentView(root)
panel = DeckControlsPanel(activity, {}, {}, {}, bridge)
root.addView(panel)
descendants(panel).filterIsInstance<TextView>().first { it.text == activity.getString(R.string.deck_tab_gamepad) }.performClick()
val trackpad = child("TrackpadView")
trackpad.layout(0, 0, 300, 300)
touch(trackpad, MotionEvent.ACTION_DOWN, 200f, 100f)
touch(trackpad, MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 200f, 100f, fingers = 2)
assertEquals(32 or 128, JoyConPadTest.RecordingWriter.grips)
}
@After fun close() {
root.removeAllViews()
bridge.stop()
DeckControls.releaseAll()
controller.pause().stop().destroy()
}
@Test fun switchingTheOtherStickKeepsTrackpadContactAndClickHeld() {
val stick = child("StickView")
stick.layout(0, 0, 300, 300)
touch(stick, MotionEvent.ACTION_DOWN, 150f, 150f)
touch(stick, MotionEvent.ACTION_MOVE, 240f, 150f)
assertTrue(state().leftX > 0f)
val position = JoyConPadTest.RecordingWriter.deckPads.copyOf()
descendants(stick.parent as View).first { it.contentDescription == activity.getString(R.string.deck_surface_switch) }.performClick()
assertEquals(0f, state().leftX)
assertTrackpadStillHeld(position)
root.removeView(panel)
assertEquals(0, JoyConPadTest.RecordingWriter.grips)
}
@Test fun removingDirectionPadReleasesOnlyItsOwnInput() {
val dpad = child("DirectionPad")
dpad.layout(0, 0, 300, 300)
touch(dpad, MotionEvent.ACTION_DOWN, 150f, 30f)
assertTrue(state().up)
val position = JoyConPadTest.RecordingWriter.deckPads.copyOf()
(dpad.parent as ViewGroup).removeView(dpad)
assertFalse(state().up)
assertTrackpadStillHeld(position)
}
@Test fun removingFaceButtonsReleasesOnlyTheirOwnInput() {
val buttons = child("FaceButtons")
buttons.layout(0, 0, 300, 300)
touch(buttons, MotionEvent.ACTION_DOWN, 150f, 240f)
assertTrue(state().isDown(PadState.A))
val position = JoyConPadTest.RecordingWriter.deckPads.copyOf()
(buttons.parent as ViewGroup).removeView(buttons)
assertFalse(state().isDown(PadState.A))
assertTrackpadStillHeld(position)
}
private fun assertTrackpadStillHeld(position: ShortArray) {
assertEquals(32 or 128, JoyConPadTest.RecordingWriter.grips)
assertArrayEquals(position, JoyConPadTest.RecordingWriter.deckPads)
}
private fun state() = JoyConPadTest.RecordingWriter.pads[0]!!
private fun child(name: String) = descendants(panel).first { it.javaClass.simpleName == name }
private fun descendants(view: View): Sequence<View> = sequence {
yield(view)
if (view is ViewGroup) for (i in 0 until view.childCount) yieldAll(descendants(view.getChildAt(i)))
}
private fun touch(view: View, action: Int, x: Float, y: Float, fingers: Int = 1) {
val properties = Array(fingers) { i -> MotionEvent.PointerProperties().apply { id = i; toolType = MotionEvent.TOOL_TYPE_FINGER } }
val coords = Array(fingers) { MotionEvent.PointerCoords().apply { this.x = x; this.y = y; pressure = 1f; size = 1f } }
val event = MotionEvent.obtain(1000, 1010, action, fingers, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, 0)
try { assertTrue(view.onTouchEvent(event)) } finally { event.recycle() }
}
}