diff --git a/dadb/src/main/kotlin/dadb/adbserver/AdbServer.kt b/dadb/src/main/kotlin/dadb/adbserver/AdbServer.kt index a481f13..e88bf46 100644 --- a/dadb/src/main/kotlin/dadb/adbserver/AdbServer.kt +++ b/dadb/src/main/kotlin/dadb/adbserver/AdbServer.kt @@ -50,6 +50,12 @@ object AdbServer { connectTimeout: Int = 0, socketTimeout: Int = 0 ): Dadb { + if (deviceQuery.startsWith("first:")) { + val filter = Regex(deviceQuery.removePrefix("first:")) + return listDadbs(adbServerHost, adbServerPort).first { + it is AdbServerDadb && it.name.contains(filter) + } + } val name = deviceQuery .removePrefix("host:") // Use the device query without the host: prefix .removePrefix("transport:") // If it's a serial-number, just show that @@ -123,7 +129,7 @@ private class AdbServerDadb constructor( private val host: String, private val port: Int, private val deviceQuery: String, - private val name: String, + val name: String, private val connectTimeout: Int = 0, private val socketTimeout: Int = 0, ) : Dadb { @@ -131,7 +137,7 @@ private class AdbServerDadb constructor( private val supportedFeatures: Set init { - supportedFeatures = open("host:features").use { + supportedFeatures = open("host-serial:$name:features").use { val features = AdbServer.readString(DataInputStream(it.source.inputStream())) features.split(",").toSet() } diff --git a/dadb/src/test/kotlin/dadb/AdbServerTest.kt b/dadb/src/test/kotlin/dadb/AdbServerTest.kt index fa4d611..04d5ba2 100644 --- a/dadb/src/test/kotlin/dadb/AdbServerTest.kt +++ b/dadb/src/test/kotlin/dadb/AdbServerTest.kt @@ -17,6 +17,6 @@ internal class AdbServerTest : DadbTest() { } override fun localEmulator(body: (dadb: Dadb) -> Unit) { - AdbServer.createDadb("localhost", 5037).use(body) + AdbServer.createDadb("localhost", 5037, "first:").use(body) } -} \ No newline at end of file +} diff --git a/dadb/src/test/kotlin/dadb/adbserver/AdbBinaryTest.kt b/dadb/src/test/kotlin/dadb/adbserver/AdbBinaryTest.kt index 1b288c2..ea0f26b 100644 --- a/dadb/src/test/kotlin/dadb/adbserver/AdbBinaryTest.kt +++ b/dadb/src/test/kotlin/dadb/adbserver/AdbBinaryTest.kt @@ -12,7 +12,7 @@ internal class AdbBinaryTest { repeat(10) { killServer() AdbBinary.ensureServerRunning("localhost", 5037) - val output = AdbServer.createDadb("localhost", 5037, connectTimeout = 1000, socketTimeout = 1000).shell("echo hello").allOutput + val output = AdbServer.createDadb("localhost", 5037, deviceQuery = "first:", connectTimeout = 1000, socketTimeout = 1000).shell("echo hello").allOutput assertThat(output).isEqualTo("hello\n") } }