mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
version: answer 1.7 to head units offering 4.x and 6.x too, as they accept it
This commit is contained in:
1 parent
6efdad5e53
commit
c7077f2a57
3 files changed
+15
-6
No files matched your search
@@ -1,6 +1,10 @@
|
|||||||
package app.seb3thehacker.gearslip
|
package app.seb3thehacker.gearslip
|
||||||
|
|
||||||
/** Advertises our supported 1.x version, as Android Auto does for older head units. */
|
/**
|
||||||
|
* Advertises our supported 1.x version, as Android Auto does for older head units. Head units that
|
||||||
|
* offer a newer major version (LIVI asks for 6.1, a RAV4 and the DHU for 4.2) still accept a 1.x
|
||||||
|
* answer, so only a major version of 0 is refused.
|
||||||
|
*/
|
||||||
internal object ProtocolVersion {
|
internal object ProtocolVersion {
|
||||||
data class Response(val major: Int, val minor: Int, val supported: Boolean) {
|
data class Response(val major: Int, val minor: Int, val supported: Boolean) {
|
||||||
val bytes: ByteArray get() = byteArrayOf(
|
val bytes: ByteArray get() = byteArrayOf(
|
||||||
@@ -9,5 +13,5 @@ internal object ProtocolVersion {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun respond(major: Int, minor: Int): Response = Response(1, 7, major == 1 && minor in 0..0xffff)
|
fun respond(major: Int, minor: Int): Response = Response(1, 7, major >= 1 && minor in 0..0xffff)
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ class ConnectionLifecycleTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test fun `unsupported version sends rejection and ends without waiting for peer EOF`() {
|
@Test fun `unsupported version sends rejection and ends without waiting for peer EOF`() {
|
||||||
val input = CountingInput(message(1, byteArrayOf(0, 2, 0, 0)))
|
val input = CountingInput(message(1, byteArrayOf(0, 0, 0, 9)))
|
||||||
val output = ByteArrayOutputStream()
|
val output = ByteArrayOutputStream()
|
||||||
val runner = GearslipRunner(input, output, ::identity)
|
val runner = GearslipRunner(input, output, ::identity)
|
||||||
runner.run()
|
runner.run()
|
||||||
@@ -112,7 +112,7 @@ class ConnectionLifecycleTest {
|
|||||||
val parser = Frames.Parser()
|
val parser = Frames.Parser()
|
||||||
parser.append(output.toByteArray(), output.size())
|
parser.append(output.toByteArray(), output.size())
|
||||||
val response = requireNotNull(parser.next())
|
val response = requireNotNull(parser.next())
|
||||||
assertArrayEquals(byteArrayOf(0, 2) + ProtocolVersion.respond(2, 0).bytes, response.payload)
|
assertArrayEquals(byteArrayOf(0, 2) + ProtocolVersion.respond(0, 9).bytes, response.payload)
|
||||||
assertEquals("Unsupported protocol", SessionStatus.state.value.headline)
|
assertEquals("Unsupported protocol", SessionStatus.state.value.headline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,13 @@ class ProtocolVersionTest {
|
|||||||
assertArrayEquals(byteArrayOf(0, 1, 0, 7, 0, 0), ProtocolVersion.respond(1, 9).bytes)
|
assertArrayEquals(byteArrayOf(0, 1, 0, 7, 0, 0), ProtocolVersion.respond(1, 9).bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun `unsupported major is never reported as a successful downgrade`() {
|
@Test fun `newer head units get the 1x answer they accept`() {
|
||||||
val response = ProtocolVersion.respond(4, 3)
|
assertArrayEquals(byteArrayOf(0, 1, 0, 7, 0, 0), ProtocolVersion.respond(4, 2).bytes)
|
||||||
|
assertArrayEquals(byteArrayOf(0, 1, 0, 7, 0, 0), ProtocolVersion.respond(6, 1).bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun `major version 0 is refused`() {
|
||||||
|
val response = ProtocolVersion.respond(0, 9)
|
||||||
assertFalse(response.supported)
|
assertFalse(response.supported)
|
||||||
assertArrayEquals(byteArrayOf(0, 1, 0, 7, -1, -1), response.bytes)
|
assertArrayEquals(byteArrayOf(0, 1, 0, 7, -1, -1), response.bytes)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user