mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-12-01 07:40:31 +01:00
Touch works on cars that never send a press, such as a Subaru Harman unit, and a second version request before TLS is answered too, which Open Headunit waits for
This commit is contained in:
1 parent
2637212961
commit
3b9e5b591e
3 files changed
+114
-5
No files matched your search
@@ -433,7 +433,12 @@ class GearslipRunner(
|
||||
}
|
||||
|
||||
private fun onVersionRequest(body: ByteArray) {
|
||||
if (state != State.WAIT_VERSION) return
|
||||
// Android Auto answers every version request that comes before TLS. Open Headunit asks
|
||||
// for 6.1, then again for 1.6 when it gets 1.7 back, and both sides waited while
|
||||
// Gearslip ignored the second one (issue #163).
|
||||
val again = state == State.TLS_HANDSHAKE && !tlsBytesSeen
|
||||
if (state != State.WAIT_VERSION && !again) return
|
||||
if (again) log.i("another VersionRequest before TLS - answering it too")
|
||||
if (body.size < 4) {
|
||||
log.w("VersionRequest too short (${body.size} bytes)")
|
||||
return
|
||||
@@ -458,8 +463,12 @@ class GearslipRunner(
|
||||
log.i("awaiting ClientHello - the head unit is the TLS client, we are the server")
|
||||
}
|
||||
|
||||
/** The car has started TLS, so a VersionRequest now would be out of turn. */
|
||||
@Volatile private var tlsBytesSeen = false
|
||||
|
||||
private fun onHandshake(body: ByteArray) {
|
||||
if (state != State.TLS_HANDSHAKE && state != State.WAIT_AUTH) return
|
||||
tlsBytesSeen = true
|
||||
log.i("<- EncapsulatedSSL (${body.size} bytes)")
|
||||
val replies = try {
|
||||
val preparedTls = tls
|
||||
@@ -811,12 +820,12 @@ class GearslipRunner(
|
||||
openChannel(channel)
|
||||
}
|
||||
|
||||
/** The turn card on the instrument cluster, for a car with a cluster screen: experimental, off by default. */
|
||||
/** The turn card on the instrument cluster, for a car with a cluster screen: off by default. */
|
||||
private fun startClusterVideo(serviceDiscoveryResponse: ByteArray) {
|
||||
val sink = ServiceDiscovery.findClusterVideoService(serviceDiscoveryResponse) ?: return
|
||||
log.i("cluster video sink: channel=${sink.serviceId} display=${sink.displayId} type=${sink.displayType}")
|
||||
if (!CarSettings.experimentalFeaturesEnabled.value || !CarSettings.clusterVideoEnabled.value) {
|
||||
log.i("cluster screen is off in the car's Settings (experimental) - leaving that sink alone")
|
||||
if (!CarSettings.clusterVideoEnabled.value) {
|
||||
log.i("cluster screen is off in the car's Settings - leaving that sink alone")
|
||||
return
|
||||
}
|
||||
val context = app.seb3thehacker.gearslip.car.CarEnvironment.appContext ?: return
|
||||
@@ -1100,9 +1109,17 @@ class GearslipRunner(
|
||||
}
|
||||
// Time the next frame against this tap: see [reportTouchLatency].
|
||||
if (action == ACTION_DOWN || action == ACTION_UP) touchAtUs = System.nanoTime() / 1000
|
||||
projection?.onTouch(action, actionIndex, points)
|
||||
val before = touchSequence.fixed
|
||||
val sent = touchSequence.next(InputProtocol.Touch(action, actionIndex, points))
|
||||
if (touchSequence.fixed > before && touchSequence.fixed <= 3) {
|
||||
log.i("touch: the car's gesture had no press, sent as ${sent.joinToString { it.action.toString() }}")
|
||||
}
|
||||
sent.forEach { projection?.onTouch(it.action, it.actionIndex, it.points) }
|
||||
}
|
||||
|
||||
/** Repairs gestures from cars that never send a press (issue #81). */
|
||||
private val touchSequence = app.seb3thehacker.gearslip.protocol.TouchSequence()
|
||||
|
||||
/** This drive's taps came in past the edge of the picture, so the car reports in its panel's size. */
|
||||
@Volatile private var touchPanelCoordinates = false
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package app.seb3thehacker.gearslip.protocol
|
||||
|
||||
/**
|
||||
* Turns the car's touches into gestures Android accepts. Android only treats a touch as a press
|
||||
* when it starts with ACTION_DOWN, and some head units never send one: a 2020 Subaru (Harman,
|
||||
* issue #81) starts each press with POINTER_DOWN, sends quick taps as a bare UP, and lifts the
|
||||
* last of two fingers with UP twice. Nothing on the screen reacted to its taps. This keeps track
|
||||
* of which fingers are down and rewrites, or adds, the actions a well-formed gesture needs. A car
|
||||
* that already sends proper gestures passes through unchanged.
|
||||
*/
|
||||
internal class TouchSequence {
|
||||
private val down = mutableSetOf<Int>()
|
||||
|
||||
/** How many touches this drive needed fixing, for the log. */
|
||||
var fixed = 0
|
||||
private set
|
||||
|
||||
/** The touches to hand on, in order: usually [touch] alone, sometimes a press added before it. */
|
||||
fun next(touch: InputProtocol.Touch): List<InputProtocol.Touch> {
|
||||
val one = touch.points.size == 1
|
||||
val out = when (touch.action) {
|
||||
DOWN -> listOf(touch)
|
||||
POINTER_DOWN -> if (down.isEmpty() && one) listOf(touch.copy(action = DOWN)) else listOf(touch)
|
||||
MOVE -> if (down.isEmpty() && one) listOf(touch.copy(action = DOWN), touch) else listOf(touch)
|
||||
UP -> when {
|
||||
!one -> listOf(touch.copy(action = POINTER_UP))
|
||||
down.isEmpty() -> listOf(touch.copy(action = DOWN), touch)
|
||||
else -> listOf(touch)
|
||||
}
|
||||
POINTER_UP -> if (one) listOf(touch.copy(action = UP)) else listOf(touch)
|
||||
else -> listOf(touch)
|
||||
}
|
||||
if (out.size != 1 || out[0].action != touch.action) fixed++
|
||||
out.forEach(::track)
|
||||
return out
|
||||
}
|
||||
|
||||
private fun track(touch: InputProtocol.Touch) {
|
||||
val id = touch.points[touch.actionIndex].id
|
||||
when (touch.action) {
|
||||
DOWN -> { down.clear(); down += touch.points.map { it.id } }
|
||||
POINTER_DOWN -> down += id
|
||||
POINTER_UP -> down -= id
|
||||
UP -> down.clear()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val DOWN = 0
|
||||
const val UP = 1
|
||||
const val MOVE = 2
|
||||
const val POINTER_DOWN = 5
|
||||
const val POINTER_UP = 6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package app.seb3thehacker.gearslip.protocol
|
||||
|
||||
import app.seb3thehacker.gearslip.TouchPoint
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class TouchSequenceTest {
|
||||
private fun t(action: Int, vararg ids: Int, index: Int = 0) =
|
||||
InputProtocol.Touch(action, index, ids.map { TouchPoint(it, 10f, 20f) })
|
||||
|
||||
private fun TouchSequence.actions(vararg touches: InputProtocol.Touch) =
|
||||
touches.flatMap { next(it) }.map { it.action }
|
||||
|
||||
@Test fun `a proper gesture passes through unchanged`() {
|
||||
val s = TouchSequence()
|
||||
assertEquals(listOf(0, 2, 5, 6, 1), s.actions(t(0, 1), t(2, 1), t(5, 1, 2, index = 1), t(6, 1, 2, index = 1), t(1, 1)))
|
||||
assertEquals(0, s.fixed)
|
||||
}
|
||||
|
||||
@Test fun `a press that starts with a second finger becomes a press`() {
|
||||
// The Subaru in issue #81: 5, 2, 1.
|
||||
assertEquals(listOf(0, 2, 1), TouchSequence().actions(t(5, 1), t(2, 1), t(1, 1)))
|
||||
}
|
||||
|
||||
@Test fun `a bare lift gets a press before it`() {
|
||||
assertEquals(listOf(0, 1, 0, 1), TouchSequence().actions(t(1, 1), t(1, 1)))
|
||||
}
|
||||
|
||||
@Test fun `two fingers lifted as two ups end as pointer up then up`() {
|
||||
val s = TouchSequence()
|
||||
assertEquals(listOf(0, 5, 6, 1), s.actions(t(0, 1), t(5, 1, 2, index = 1), t(1, 1, 2, index = 1), t(1, 1)))
|
||||
}
|
||||
|
||||
@Test fun `a move with nothing down starts a press`() {
|
||||
assertEquals(listOf(0, 2, 1), TouchSequence().actions(t(2, 1), t(1, 1)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user