com.avito.android.runner.devices.internal.AbstractDevice.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of impl Show documentation
Show all versions of impl Show documentation
Collection of infrastructure libraries and gradle plugins of Avito Android project
package com.avito.android.runner.devices.internal
import com.avito.android.Result
import com.avito.android.waiter.waitForCondition
import com.avito.logger.LoggerFactory
import com.avito.logger.create
import com.avito.runner.service.worker.device.adb.Adb
import com.avito.utils.ProcessRunner
import kotlinx.coroutines.delay
import java.io.File
import java.time.Duration
internal abstract class AbstractDevice(
protected val loggerFactory: LoggerFactory,
protected val processRunner: ProcessRunner,
) : Device {
private val logger = loggerFactory.create()
protected abstract val adb: Adb
override fun redirectLogcatToFile(
file: File,
tags: Collection
) {
val tagsString = if (tags.isEmpty()) {
""
} else {
" ${tags.joinToString(" ")}"
}
// TODO stop endless process
processRunner.spawn(
command = "$adb -s $serial logcat$tagsString",
outputTo = file
)
}
protected suspend fun isBootCompleted() =
waitForCommand(
command = {
processRunner.run(
command = "$adb -s $serial $CHECK_BOOT_COMPLETED_COMMAND",
timeout = Duration.ofSeconds(10)
)
}
)
protected suspend fun waitForCommand(
command: suspend () -> Result,
attempts: Int = 12,
frequencySec: Long = 5,
timeoutSec: Long = 60
) = waitForCondition(
conditionName = "Wait device with serial: $serial",
maxAttempts = attempts,
onSuccess = { conditionName: String, durationMs: Long, attempt: Int ->
logger.debug("$conditionName succeed in $durationMs at attempt=$attempt")
},
sleepAction = { frequencyMs: Long -> delay(frequencyMs) },
frequencySeconds = frequencySec,
timeoutSec = timeoutSec,
condition = command
)
}
private const val CHECK_BOOT_COMPLETED_COMMAND = "shell getprop sys.boot_completed"
© 2015 - 2024 Weber Informatics LLC | Privacy Policy