mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: hold XInput rumble until the game changes it, instead of stopping after a second (#938)
This commit is contained in:
1 parent
2c37f79701
commit
3f3ed3923b
7 files changed
+283
-43
No files matched your search
@@ -35,7 +35,7 @@ class RumbleComponentTest {
|
||||
vibrator = if (Build.VERSION.SDK_INT >= 31) context.getSystemService(VibratorManager::class.java).defaultVibrator
|
||||
else context.getSystemService(Vibrator::class.java)
|
||||
shadowOf(vibrator).setHasVibrator(true)
|
||||
rumble = RumbleComponent().also { it.attach(context); it.start() }
|
||||
rumble = RumbleComponent().also { it.motorLooper = Looper.getMainLooper(); it.attach(context); it.start() }
|
||||
}
|
||||
|
||||
@After fun stopListener() { rumble.stop() }
|
||||
@@ -78,24 +78,73 @@ class RumbleComponentTest {
|
||||
assertFalse("the phone buzzed as well", shadowOf(vibrator).isVibrating)
|
||||
}
|
||||
|
||||
@Test fun repeatedAndRapidEffectsDoNotRestartTheMotors() {
|
||||
@Test fun repeatedAndRapidEffectsDoNotRestartTheMotorsButTheLatestStillLands() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
activeController(PAD_ID)
|
||||
repeat(5) { effect(strong = 40000, weak = 1000) }
|
||||
effect(strong = 20000, weak = 1000)
|
||||
effect(strong = 30000, weak = 1000)
|
||||
assertEquals("a stream of packets restarted the motor each time", 1, pad.played.size)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(java.time.Duration.ofMillis(RumbleComponent.MIN_GAP_MS))
|
||||
effect(strong = 40000, weak = 1000)
|
||||
assertEquals("the same strength, still playing, was started again", 1, pad.played.size)
|
||||
effect(strong = 20000, weak = 1000)
|
||||
assertEquals(Triple(20000, 1000, 5000L), pad.played.last())
|
||||
idle(RumbleComponent.MIN_GAP_MS)
|
||||
assertEquals("the last change inside the gap was lost",
|
||||
listOf(Triple(40000, 1000, 5000L), Triple(30000, 1000, 5000L)), pad.played)
|
||||
effect(strong = 30000, weak = 1000)
|
||||
assertEquals("the same strength, still playing, was started again", 2, pad.played.size)
|
||||
effect(strong = 0, weak = 0)
|
||||
assertFalse(pad.vibrating)
|
||||
effect(strong = 20000, weak = 1000)
|
||||
assertTrue("an effect right after a stop was dropped", pad.vibrating)
|
||||
}
|
||||
|
||||
@Test fun aHeldEffectKeepsTheMotorsRunningUntilTheGameStopsIt() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
activeController(PAD_ID)
|
||||
effect(strong = 40000, weak = 20000, ms = RumbleComponent.HOLD_MS)
|
||||
assertEquals(listOf(Triple(40000, 20000, RumbleComponent.HOLD_EFFECT_MS)), pad.played)
|
||||
idle(RumbleComponent.KEEPALIVE_MS * 4 + 100)
|
||||
assertEquals("the held effect was not re-armed before it ran out", 5, pad.played.size)
|
||||
effect(strong = 40000, weak = 20000, ms = RumbleComponent.HOLD_MS)
|
||||
assertEquals("a repeat of the held strength restarted the motors", 5, pad.played.size)
|
||||
effect(strong = 0, weak = 0)
|
||||
assertFalse(pad.vibrating)
|
||||
idle(RumbleComponent.KEEPALIVE_MS * 4 + 100)
|
||||
assertEquals("the keepalive restarted the motors after a stop", 5, pad.played.size)
|
||||
assertFalse(pad.vibrating)
|
||||
}
|
||||
|
||||
@Test fun aHeldEffectFollowsTheGamesNewStrength() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
activeController(PAD_ID)
|
||||
effect(strong = 40000, weak = 0, ms = RumbleComponent.HOLD_MS)
|
||||
effect(strong = 10000, weak = 0, ms = RumbleComponent.HOLD_MS)
|
||||
idle(RumbleComponent.KEEPALIVE_MS * 2)
|
||||
assertTrue(pad.played.drop(1).isNotEmpty())
|
||||
assertTrue("the keepalive replayed an old strength", pad.played.drop(1).all { it.first == 10000 })
|
||||
}
|
||||
|
||||
@Test fun aTimedEffectIsNotRearmed() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
activeController(PAD_ID)
|
||||
effect(strong = 40000, weak = 0, ms = 300)
|
||||
idle(RumbleComponent.KEEPALIVE_MS * 3)
|
||||
assertEquals(listOf(Triple(40000, 0, 300L)), pad.played)
|
||||
}
|
||||
|
||||
@Test fun disablingStopsTheKeepalive() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
activeController(PAD_ID)
|
||||
effect(ms = RumbleComponent.HOLD_MS)
|
||||
ControllerPrefs.setRumble(context, false)
|
||||
idle(RumbleComponent.KEEPALIVE_MS * 3)
|
||||
assertEquals(1, pad.played.size)
|
||||
assertFalse(pad.vibrating)
|
||||
}
|
||||
|
||||
@Test fun aControllerWithoutMotorsFallsBackToThePhone() {
|
||||
rumble.controllerMotors = { null }
|
||||
activeController(PAD_ID)
|
||||
@@ -163,12 +212,14 @@ class RumbleComponentTest {
|
||||
(slots as java.util.concurrent.atomic.AtomicIntegerArray).set(slot, id)
|
||||
}
|
||||
|
||||
private fun effect(strong: Int = 65535, weak: Int = 65535, slot: Int = 0) {
|
||||
private fun effect(strong: Int = 65535, weak: Int = 65535, slot: Int = 0, ms: Int = 5000) {
|
||||
val int = Int::class.javaPrimitiveType
|
||||
RumbleComponent::class.java.getDeclaredMethod("buzz", int, int, int, int)
|
||||
.apply { isAccessible = true }.invoke(rumble, strong, weak, 5000, slot)
|
||||
.apply { isAccessible = true }.invoke(rumble, strong, weak, ms, slot)
|
||||
}
|
||||
|
||||
private fun idle(ms: Long) = shadowOf(Looper.getMainLooper()).idleFor(java.time.Duration.ofMillis(ms))
|
||||
|
||||
private class FakeMotors : RumbleComponent.Motors {
|
||||
override val name = "fake pad"
|
||||
val played = mutableListOf<Triple<Int, Int, Long>>()
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.zip.ZipFile
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
@@ -27,13 +30,15 @@ class SessionLogShareZipTest {
|
||||
"Authorization: Bearer abc.def.ghi\n" +
|
||||
"kept: EResult 5, app 1086940, steamapps/common/Game\n"
|
||||
)
|
||||
File(logs, "stores").apply { mkdirs() }.resolve("stores-2026-10-08.log").writeText("epic: f_token=zzzzzzzz12 window 32\n")
|
||||
// StoreLogFiles.prune, started by App.onCreate, deletes a stores log named for a day over a week old.
|
||||
val storesLog = "stores-" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()) + ".log"
|
||||
File(logs, "stores").apply { mkdirs() }.resolve(storesLog).writeText("epic: f_token=zzzzzzzz12 window 32\n")
|
||||
File(logs, SessionPaths.TOOLS_DIR).apply { mkdirs() }.resolve("flatpak-install.log").writeText("== install\nCookie: steamLoginSecure=76561198000000000%7C%7Ceyabc\n")
|
||||
|
||||
val zip = SessionLogShare.zipFolder(app, session)!!
|
||||
assertTrue(zip.path.startsWith(File(app.cacheDir, "share").path))
|
||||
val text = ZipFile(zip).use { z -> z.entries().toList().associate { e -> e.name to z.getInputStream(e).bufferedReader().readText() } }
|
||||
assertTrue(text.keys.containsAll(listOf("2026-10-08-01-steam/session.log", "stores/stores-2026-10-08.log", "tools/flatpak-install.log")))
|
||||
assertTrue(text.keys.containsAll(listOf("2026-10-08-01-steam/session.log", "stores/$storesLog", "tools/flatpak-install.log")))
|
||||
val all = text.values.joinToString("\n")
|
||||
for (secret in listOf("0a1b2c3d4e5f", "deadbeefcafe", "abcdef123456", "someone@example.com", "AUTHCODE123", "abc.def.ghi", "zzzzzzzz12", "eyabc")) {
|
||||
assertFalse("$secret survived", all.contains(secret))
|
||||
|
||||
Reference in new issue
Block a user