Fix controller rings on linked data dirs, route rumble to the controller, capture the mouse for pointer locks (#242)

- #166: export the fake-input ring paths with the spelling the session tree is bound under
  (Context.getFilesDir(), /data/user/0/...) instead of the canonical path. Where /data/user/0
  resolves to /data/data (ColorOS 16) the guest has nothing bound at the canonical prefix, so
  libfakeinput could not open the rings and every pad, physical and on-screen, was dead. The ring
  path logic moves to FakeInputRingPaths so it can be unit-tested without the native library.
- #219: play a game's rumble on the physical controller that last drove the pad, when Android
  exposes its motors (strong and weak separately on Android 12+), and fall back to the device's
  vibrator for the on-screen pad or a controller without rumble. PadBridge records the active
  controller; the on-screen pad taking over moves rumble back to the phone.
- #153: when a program takes a pointer lock (a mouse-look game through gamescope), capture a
  physical mouse and send its raw deltas as relative motion, so the camera no longer stops where
  Android's pointer meets the screen edge. Capture is released for the drawer, the PC keyboard,
  picture in picture, focus loss and pause, and when the lock ends.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-05 07:33:33 -04:00
1 parent eaa4a7a047
commit 472bb28c88
8 files changed
+383 -50

No files matched your search

@@ -0,0 +1,53 @@
package com.droiddeck.launcher.input
import java.io.File
import java.nio.file.Files
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
/**
* The ring paths handed to the guest (FAKE_EVDEV_MEMFD_PATHS) must keep the spelling the session
* tree is bound under. On ColorOS 16 /data/user/0 resolves to /data/data, the guest only has the
* first bound, and a canonical export left every pad dead (#166). A symlinked directory stands in
* for that here.
*/
class FakeInputRingPathTest {
private lateinit var base: File
private lateinit var real: File
private lateinit var link: File
@Before fun setUp() {
base = Files.createTempDirectory("ring-path").toFile()
real = File(base, "data-data").apply { mkdirs() }
link = File(base, "data-user-0")
Files.createSymbolicLink(link.toPath(), real.toPath())
}
@After fun tearDown() {
base.deleteRecursively()
}
@Test fun ringsSitBesideTheFakeInputNodes() {
val fakeInputDir = File(link, "files/session/dev/input")
assertEquals(File(link, "files/session/dev/fakeinput-rings/ring2"), FakeInputRingPaths.ringFile(fakeInputDir, 2))
}
@Test fun theExportKeepsTheBoundSpellingThroughALinkedDataDirectory() {
val fakeInputDir = File(link, "files/session/dev/input").apply { mkdirs() }
val ring = FakeInputRingPaths.ringFile(fakeInputDir, 0)!!.apply { parentFile!!.mkdirs(); writeText("") }
// The link really does resolve elsewhere, as /data/user/0 does on the affected devices.
assertTrue(ring.canonicalPath.startsWith(real.canonicalPath + "/"))
val exported = FakeInputRingPaths.exportPath(ring)
assertEquals(File(link, "files/session/dev/fakeinput-rings/ring0").path, exported)
assertFalse("$exported resolved through the link", exported.startsWith(real.path + "/"))
assertTrue("$exported does not open", File(exported).isFile)
}
@Test fun aRelativeInputDirIsExportedAbsolute() {
val exported = FakeInputRingPaths.exportPath(FakeInputRingPaths.ringFile(File("session/dev/input"), 1)!!)
assertTrue(exported, File(exported).isAbsolute)
assertTrue(exported, exported.endsWith("/session/dev/fakeinput-rings/ring1"))
}
}
@@ -8,6 +8,7 @@ import android.os.Looper
import android.os.Vibrator
import android.os.VibratorManager
import com.droiddeck.launcher.input.ControllerPrefs
import com.droiddeck.launcher.input.PadBridge
import java.io.IOException
import org.junit.After
import org.junit.Before
@@ -68,12 +69,74 @@ class RumbleComponentTest {
assertTrue(shadowOf(vibrator).isVibrating)
}
private fun effect() {
// Inject a decoded force-feedback packet; transport is outside this preference test.
RumbleComponent::class.java.getDeclaredMethod("buzz", Int::class.javaPrimitiveType, Int::class.javaPrimitiveType)
.apply { isAccessible = true }.invoke(rumble, 65535, 5000)
@Test fun aControllerWithMotorsGetsTheEffectInsteadOfThePhone() {
val pad = FakeMotors()
rumble.controllerMotors = { id -> if (id == PAD_ID) pad else null }
activeController(PAD_ID)
effect(strong = 40000, weak = 1000)
assertEquals(listOf(Triple(40000, 1000, 5000L)), pad.played)
assertFalse("the phone buzzed as well", shadowOf(vibrator).isVibrating)
}
@Test fun aControllerWithoutMotorsFallsBackToThePhone() {
rumble.controllerMotors = { null }
activeController(PAD_ID)
effect()
assertTrue(shadowOf(vibrator).isVibrating)
}
@Test fun theOnScreenPadTakingOverMovesTheEffectBackToThePhone() {
val pad = FakeMotors()
rumble.controllerMotors = { pad }
activeController(PAD_ID)
effect()
assertTrue(pad.vibrating)
activeController(PadBridge.NO_CONTROLLER)
effect()
assertFalse("the controller kept rumbling after the switch", pad.vibrating)
assertTrue(shadowOf(vibrator).isVibrating)
}
@Test fun aStopPacketDisablingAndStoppingAllEndTheControllersEffect() {
val pad = FakeMotors()
rumble.controllerMotors = { pad }
activeController(PAD_ID)
effect()
effect(strong = 0, weak = 0)
assertFalse(pad.vibrating)
effect()
ControllerPrefs.setRumble(context, false)
shadowOf(Looper.getMainLooper()).idle()
assertFalse(pad.vibrating)
ControllerPrefs.setRumble(context, true)
shadowOf(Looper.getMainLooper()).idle()
effect()
rumble.stop()
assertFalse(pad.vibrating)
}
@After fun clearActiveController() { activeController(PadBridge.NO_CONTROLLER) }
private fun activeController(id: Int) {
PadBridge::class.java.getDeclaredField("activeControllerId").apply { isAccessible = true }.setInt(null, id)
}
private fun effect(strong: Int = 65535, weak: Int = 65535) {
// Inject a decoded force-feedback packet; transport is outside these tests.
RumbleComponent::class.java.getDeclaredMethod("buzz", Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType)
.apply { isAccessible = true }.invoke(rumble, strong, weak, 5000)
}
private class FakeMotors : RumbleComponent.Motors {
override val name = "fake pad"
val played = mutableListOf<Triple<Int, Int, Long>>()
var vibrating = false
override fun play(strong: Int, weak: Int, ms: Long) { played += Triple(strong, weak, ms); vibrating = true }
override fun cancel() { vibrating = false }
}
private companion object { const val PAD_ID = 7 }
@Implements(LocalServerSocket::class)
class NoPacketsSocket {
@Implementation fun __constructor__(name: String) = Unit