Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AdbServer.list() to work with multiple adb devices #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions dadb/src/main/kotlin/dadb/adbserver/AdbServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,15 +129,15 @@ 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 {

private val supportedFeatures: Set<String>

init {
supportedFeatures = open("host:features").use {
supportedFeatures = open("host-serial:$name:features").use {
val features = AdbServer.readString(DataInputStream(it.source.inputStream()))
features.split(",").toSet()
}
Expand Down
4 changes: 2 additions & 2 deletions dadb/src/test/kotlin/dadb/AdbServerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion dadb/src/test/kotlin/dadb/adbserver/AdbBinaryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down