All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avito.android.runner.devices.internal.DeviceProviderFactoryImpl.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2024.32
Show newest version
package com.avito.android.runner.devices.internal

import com.avito.android.runner.devices.DevicesProvider
import com.avito.android.runner.devices.DevicesProviderFactory
import com.avito.android.runner.devices.internal.kubernetes.KubernetesReservationClientProvider
import com.avito.android.runner.devices.model.DeviceType
import com.avito.logger.LoggerFactory
import com.avito.runner.service.DeviceWorkerPoolProvider
import com.avito.runner.service.worker.device.adb.Adb
import com.avito.runner.service.worker.device.adb.AdbDeviceFactory
import com.avito.runner.service.worker.device.adb.AdbDevicesManager
import com.avito.runner.service.worker.device.adb.listener.RunnerMetricsConfig
import com.avito.time.TimeProvider
import com.avito.utils.ProcessRunner
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import java.io.File
import java.time.Duration

internal class DeviceProviderFactoryImpl(
    private val loggerFactory: LoggerFactory,
    private val timeProvider: TimeProvider,
    private val deviceType: DeviceType,
    private val kubernetesReservationClientProvider: KubernetesReservationClientProvider,
    private val androidDebugBridgeProvider: AndroidDebugBridgeProvider,
    private val emulatorsLogsReporterProvider: EmulatorsLogsReporterProvider,
    private val metricsConfig: RunnerMetricsConfig,
    private val processRunner: ProcessRunner,
    private val adbPullTimeout: Duration,
) : DevicesProviderFactory {

    @OptIn(ExperimentalCoroutinesApi::class)
    override fun create(
        tempLogcatDir: File,
        deviceWorkerPoolProvider: DeviceWorkerPoolProvider
    ): DevicesProvider {
        return when (deviceType) {
            DeviceType.MOCK ->
                FakeDevicesProvider(
                    loggerFactory,
                    deviceWorkerPoolProvider,
                    Channel(Channel.UNLIMITED)
                )

            DeviceType.LOCAL ->
                LocalDevicesProvider(
                    androidDebugBridge = androidDebugBridgeProvider.provide(),
                    emulatorsLogsReporter = emulatorsLogsReporterProvider.provide(tempLogcatDir),
                    devicesManager = AdbDevicesManager(
                        adb = Adb()
                    ),
                    adbDeviceFactory = AdbDeviceFactory(
                        loggerFactory = loggerFactory,
                        adb = Adb(),
                        timeProvider = timeProvider,
                        metricsConfig = null,
                        processRunner = processRunner,
                        adbPullTimeout = adbPullTimeout,
                    ),
                    loggerFactory = loggerFactory,
                    deviceWorkerPoolProvider = deviceWorkerPoolProvider
                )

            DeviceType.CLOUD ->
                KubernetesDevicesProvider(
                    client = kubernetesReservationClientProvider.provide(tempLogcatDir),
                    adbDeviceFactory = AdbDeviceFactory(
                        loggerFactory = loggerFactory,
                        adb = Adb(),
                        timeProvider = timeProvider,
                        metricsConfig = metricsConfig,
                        processRunner = processRunner,
                        adbPullTimeout = adbPullTimeout
                    ),
                    devicesManager = AdbDevicesManager(
                        adb = Adb()
                    ),
                    deviceWorkerPoolProvider = deviceWorkerPoolProvider
                )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy