-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Workday/handle_agp7
Handle agp7
- Loading branch information
Showing
14 changed files
with
260 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
torque-core/src/main/kotlin/com/workday/torque/AdbCommander.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.workday.torque | ||
|
||
import com.gojuno.commander.android.AdbDevice | ||
import com.gojuno.commander.android.adb | ||
import com.gojuno.commander.android.deviceModel | ||
import com.gojuno.commander.os.Notification | ||
import com.gojuno.commander.os.log | ||
import com.gojuno.commander.os.process | ||
import rx.Observable | ||
|
||
fun connectedAdbDevices(unbufferedOutput: Boolean = true): Observable<Set<AdbDevice>> { | ||
return process( | ||
commandAndArgs = listOf(adb, "devices"), | ||
unbufferedOutput = unbufferedOutput | ||
) | ||
.ofType(Notification.Exit::class.java) | ||
.map { it.output.readText() } | ||
.map { | ||
when (it.contains("List of devices attached")) { | ||
true -> it | ||
false -> throw IllegalStateException("Adb output is not correct: $it.") | ||
} | ||
} | ||
.retry { retryCount, exception -> | ||
val shouldRetry = retryCount < 5 && exception is IllegalStateException | ||
if (shouldRetry) { | ||
log("runningEmulators: retrying $exception.") | ||
} | ||
|
||
shouldRetry | ||
} | ||
.flatMapIterable { | ||
it | ||
.substringAfter("List of devices attached") | ||
.split(System.lineSeparator()) | ||
.map { it.trim() } | ||
.filter { it.isNotEmpty() } | ||
.filter { it.contains("online") || it.contains("device") } | ||
} | ||
.map { line -> | ||
val serial = line.substringBefore("\t") | ||
val online = when { | ||
line.contains("offline", ignoreCase = true) -> false | ||
line.contains("device", ignoreCase = true) -> true | ||
else -> throw IllegalStateException("Unknown adb output for device: $line") | ||
} | ||
AdbDevice(id = serial, online = online) | ||
} | ||
.flatMapSingle { device -> | ||
deviceModel(device).map { model -> | ||
device.copy(model = model) | ||
} | ||
} | ||
.toList() | ||
.map { it.toSet() } | ||
.doOnError { log("Error during getting connectedAdbDevices, error = $it") } | ||
} |
3 changes: 1 addition & 2 deletions
3
torque-core/src/main/kotlin/com/workday/torque/AdbDeviceFinder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.