Skip to content

Commit

Permalink
Add timeout for ADB initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Chelombitko committed Dec 11, 2024
1 parent 223f29c commit f6c24cf
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.newFixedThreadPoolContext
import java.time.Duration
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.coroutines.CoroutineContext

private const val DEFAULT_DDM_LIB_TIMEOUT = 30000
private const val DEFAULT_DDM_LIB_SLEEP_TIME = 500
private const val PRINT_LOG_TIMEOUT = 20000L

class DdmlibDeviceProvider(
private val track: Track,
private val timer: Timer,
Expand All @@ -61,10 +59,11 @@ class DdmlibDeviceProvider(

override suspend fun initialize() {
DdmPreferences.setTimeOut(DEFAULT_DDM_LIB_TIMEOUT)
AndroidDebugBridge.init(false)
@Suppress("DEPRECATION")
AndroidDebugBridge.initIfNeeded(false)
AndroidDebugBridge.addDeviceChangeListener(this)

adb = AndroidDebugBridge.createBridge(vendorConfiguration.adbPath.absolutePath, false)
adb = AndroidDebugBridge.createBridge(vendorConfiguration.adbPath.absolutePath, false, ADB_INIT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS)
logger.debug { "Created ADB bridge" }

var getDevicesCountdown = config.noDevicesTimeoutMillis
Expand All @@ -73,7 +72,7 @@ class DdmlibDeviceProvider(
logger.debug { "No devices, waiting..." }

try {
Thread.sleep(sleepTime.toLong())
delay(sleepTime)
} catch (e: InterruptedException) {
throw TimeoutException("Timeout getting device list", e)
}
Expand Down Expand Up @@ -273,4 +272,11 @@ class DdmlibDeviceProvider(

private val vendorConfiguration: AndroidConfiguration
get() = config.vendorConfiguration as AndroidConfiguration

companion object {
private val ADB_INIT_TIMEOUT = Duration.ofSeconds(60)
private const val DEFAULT_DDM_LIB_TIMEOUT = 30000
private const val DEFAULT_DDM_LIB_SLEEP_TIME = 500L
private const val PRINT_LOG_TIMEOUT = 20000L
}
}

0 comments on commit f6c24cf

Please sign in to comment.