Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Added external storage retrieval. (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunikkk authored Jun 17, 2018
1 parent 3c620fb commit 100df6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions android/src/main/kotlin/com/gojuno/commander/android/Adb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ private val buildTools: String? by lazy {
}
val aapt: String by lazy { buildTools?.let { "$buildTools/aapt" } ?: "" }

fun deviceModel(adbDevice: AdbDevice): Single<String> = process(listOf(adb, "-s", adbDevice.id, "shell", "getprop ro.product.model undefined"))
internal fun Observable<Notification>.trimmedOutput() = this
.ofType(Notification.Exit::class.java)
.toSingle()
.map { it.output.readText().trim() }

fun AdbDevice.externalStorage(): Single<String> = process(listOf(adb, "-s", id, "shell", "printenv", "EXTERNAL_STORAGE"))
.trimmedOutput()
.doOnError { log("Could not get model name of device ${adbDevice.id}, error = $it") }
.doOnError { log("Could not get external storage of device $id, error = $it") }

internal fun Observable<Notification.Exit>.trimmedOutput() = toSingle()
.map { it.output.readText().trim() }
fun AdbDevice.deviceModel(): Single<String> = process(listOf(adb, "-s", id, "shell", "getprop ro.product.model undefined"))
.trimmedOutput()
.doOnError { log("Could not get model name of device $id, error = $it") }

fun connectedAdbDevices(): Observable<Set<AdbDevice>> = process(listOf(adb, "devices"), unbufferedOutput = true)
.ofType(Notification.Exit::class.java)
Expand Down Expand Up @@ -65,7 +70,7 @@ fun connectedAdbDevices(): Observable<Set<AdbDevice>> = process(listOf(adb, "dev
AdbDevice(id = serial, online = online)
}
.flatMapSingle { device ->
deviceModel(device).map { model ->
device.deviceModel().map { model ->
device.copy(model = model)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AdbSpec : Spek({
}

it("is trimmed") {
Observable.just(Notification.Exit(file))
Observable.just<Notification>(Notification.Exit(file))
.trimmedOutput()
.test()
.assertValue("test")
Expand Down

0 comments on commit 100df6c

Please sign in to comment.