diff --git a/FloconDesktop/composeApp/src/androidMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.android.kt b/FloconDesktop/composeApp/src/androidMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.android.kt index 821e735e..b8796df5 100644 --- a/FloconDesktop/composeApp/src/androidMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.android.kt +++ b/FloconDesktop/composeApp/src/androidMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.android.kt @@ -2,7 +2,11 @@ package io.github.openflocon.flocondesktop.common import io.github.openflocon.domain.common.Either -actual fun localExecuteAdbCommand(adbPath: String, command: String): Either { +actual fun localExecuteAdbCommand( + adbPath: String, + command: String, + deviceSerial: String?, +): Either { TODO("Not yet implemented") } diff --git a/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/adb/AdbRepositoryImpl.kt b/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/adb/AdbRepositoryImpl.kt index 04aa061c..b31959e6 100644 --- a/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/adb/AdbRepositoryImpl.kt +++ b/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/adb/AdbRepositoryImpl.kt @@ -1,5 +1,6 @@ package io.github.openflocon.flocondesktop.adb +import io.github.openflocon.domain.adb.AdbCommandTargetDomainModel import io.github.openflocon.domain.adb.repository.AdbRepository import io.github.openflocon.domain.common.Either import io.github.openflocon.flocondesktop.common.askSerialToAllDevices @@ -24,8 +25,18 @@ class AdbRepositoryImpl : AdbRepository { // TODO be able to pass a serial override fun executeAdbCommand( adbPath: String, + target: AdbCommandTargetDomainModel, command: String, - ): Either = localExecuteAdbCommand(adbPath = adbPath, command = command) + ): Either { + return localExecuteAdbCommand( + adbPath = adbPath, + command = command, + deviceSerial = when(target) { + is AdbCommandTargetDomainModel.Device -> getAdbSerial(target.deviceId) + is AdbCommandTargetDomainModel.AllDevices -> null + }, + ) + } override fun executeAdbAskSerialToAllDevices( adbPath: String, diff --git a/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.kt b/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.kt index 2f6fe3da..440b3275 100644 --- a/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.kt +++ b/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.kt @@ -4,6 +4,10 @@ import io.github.openflocon.domain.common.Either expect fun localFindAdbPath(): String? -expect fun localExecuteAdbCommand(adbPath: String, command: String): Either +expect fun localExecuteAdbCommand( + adbPath: String, + command: String, + deviceSerial: String?, +): Either expect fun askSerialToAllDevices(adbPath: String, command: String, serialVariableName: String): Either diff --git a/FloconDesktop/composeApp/src/desktopMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.desktop.kt b/FloconDesktop/composeApp/src/desktopMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.desktop.kt index fd5f3da8..f1636062 100644 --- a/FloconDesktop/composeApp/src/desktopMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.desktop.kt +++ b/FloconDesktop/composeApp/src/desktopMain/kotlin/io/github/openflocon/flocondesktop/common/AdbExecutor.desktop.kt @@ -55,20 +55,28 @@ actual fun localFindAdbPath(): String? { return null } -actual fun localExecuteAdbCommand(adbPath: String, command: String): Either = try { - val devices = listConnectedDevices(adbPath) - if (devices.isEmpty() || devices.size == 1) { - singleDeviceExecuteSystemCommand(adbPath = adbPath, command = command) +actual fun localExecuteAdbCommand( + adbPath: String, + command: String, + deviceSerial: String?, +): Either = try { + if(deviceSerial != null) { + singleDeviceExecuteSystemCommand(adbPath = "$adbPath -s $deviceSerial", command = command) } else { - devices.map { serial -> - singleDeviceExecuteSystemCommand(adbPath = "$adbPath -s $serial", command = command) - }.let { - it.forEach { - // return a failure if there's on in the list - if (it is Failure) - return it + val devices = listConnectedDevices(adbPath) + if (devices.isEmpty() || devices.size == 1) { + singleDeviceExecuteSystemCommand(adbPath = adbPath, command = command) + } else { + devices.map { serial -> + singleDeviceExecuteSystemCommand(adbPath = "$adbPath -s $serial", command = command) + }.let { + it.forEach { + // return a failure if there's on in the list + if (it is Failure) + return it + } + return it.firstOrNull() ?: Success("") } - return it.firstOrNull() ?: Success("") } } } catch (t: Throwable) { diff --git a/FloconDesktop/data/core/src/commonMain/kotlin/io/github/openflocon/data/core/deeplink/repository/DeeplinkRepositoryImpl.kt b/FloconDesktop/data/core/src/commonMain/kotlin/io/github/openflocon/data/core/deeplink/repository/DeeplinkRepositoryImpl.kt index ead64703..f8ac020f 100644 --- a/FloconDesktop/data/core/src/commonMain/kotlin/io/github/openflocon/data/core/deeplink/repository/DeeplinkRepositoryImpl.kt +++ b/FloconDesktop/data/core/src/commonMain/kotlin/io/github/openflocon/data/core/deeplink/repository/DeeplinkRepositoryImpl.kt @@ -3,6 +3,7 @@ package io.github.openflocon.data.core.deeplink.repository import io.github.openflocon.data.core.deeplink.datasource.DeeplinkLocalDataSource import io.github.openflocon.data.core.deeplink.datasource.DeeplinkRemoteDataSource import io.github.openflocon.domain.Protocol +import io.github.openflocon.domain.adb.AdbCommandTargetDomainModel import io.github.openflocon.domain.adb.repository.AdbRepository import io.github.openflocon.domain.common.DispatcherProvider import io.github.openflocon.domain.deeplink.models.DeeplinkDomainModel @@ -49,7 +50,7 @@ class DeeplinkRepositoryImpl( override fun executeDeeplink(deviceIdAndPackageName: DeviceIdAndPackageNameDomainModel, adbPath: String, deeplink: String) { adbRepository.executeAdbCommand( adbPath = adbPath, - // TODO inject the device serial + target = AdbCommandTargetDomainModel.Device(deviceIdAndPackageName.deviceId), command = "shell am start -W -a android.intent.action.VIEW -d \"$deeplink\" ${deviceIdAndPackageName.packageName}", ) } diff --git a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/AdbCommandTargetDomainModel.kt b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/AdbCommandTargetDomainModel.kt new file mode 100644 index 00000000..52d139b0 --- /dev/null +++ b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/AdbCommandTargetDomainModel.kt @@ -0,0 +1,6 @@ +package io.github.openflocon.domain.adb + +sealed interface AdbCommandTargetDomainModel { + data class Device(val deviceId: String) : AdbCommandTargetDomainModel + data object AllDevices : AdbCommandTargetDomainModel +} diff --git a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/repository/AdbRepository.kt b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/repository/AdbRepository.kt index 044f0d50..87d01487 100644 --- a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/repository/AdbRepository.kt +++ b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/adb/repository/AdbRepository.kt @@ -1,5 +1,6 @@ package io.github.openflocon.domain.adb.repository +import io.github.openflocon.domain.adb.AdbCommandTargetDomainModel import io.github.openflocon.domain.common.Either interface AdbRepository { @@ -7,7 +8,11 @@ interface AdbRepository { fun getAdbSerial(deviceId: String) : String? fun saveAdbSerial(deviceId: String, serial: String) - fun executeAdbCommand(adbPath: String, command: String): Either + fun executeAdbCommand( + adbPath: String, + target: AdbCommandTargetDomainModel, + command: String, + ): Either fun executeAdbAskSerialToAllDevices( adbPath: String, diff --git a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/StartAdbForwardUseCase.kt b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/StartAdbForwardUseCase.kt index c3c07729..d4d1b4c5 100644 --- a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/StartAdbForwardUseCase.kt +++ b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/StartAdbForwardUseCase.kt @@ -1,6 +1,7 @@ package io.github.openflocon.domain.settings.usecase import io.github.openflocon.domain.Constant +import io.github.openflocon.domain.adb.AdbCommandTargetDomainModel import io.github.openflocon.domain.adb.repository.AdbRepository import io.github.openflocon.domain.common.Either import io.github.openflocon.domain.common.Failure @@ -13,8 +14,11 @@ class StartAdbForwardUseCase( operator fun invoke(): Either { val adbPath = settingsRepository.getAdbPath() return if (adbPath != null) { - adbRepository.executeAdbCommand(adbPath = adbPath, command = "reverse tcp:${Constant.SERVER_PORT} tcp:${Constant.SERVER_PORT}") - .mapSuccess { Unit } + adbRepository.executeAdbCommand( + adbPath = adbPath, + command = "reverse tcp:${Constant.SERVER_PORT} tcp:${Constant.SERVER_PORT}", + target = AdbCommandTargetDomainModel.AllDevices, + ).mapSuccess { Unit } } else { Failure(Throwable("adb path is empty")) } diff --git a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/TestAdbUseCase.kt b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/TestAdbUseCase.kt index 0fa15312..65456982 100644 --- a/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/TestAdbUseCase.kt +++ b/FloconDesktop/domain/src/commonMain/kotlin/io/github/openflocon/domain/settings/usecase/TestAdbUseCase.kt @@ -1,5 +1,6 @@ package io.github.openflocon.domain.settings.usecase +import io.github.openflocon.domain.adb.AdbCommandTargetDomainModel import io.github.openflocon.domain.adb.repository.AdbRepository import io.github.openflocon.domain.common.Either import io.github.openflocon.domain.common.Failure @@ -12,8 +13,11 @@ class TestAdbUseCase( operator fun invoke(): Either { val adbPath = settingsRepository.getAdbPath() return if (adbPath != null) { - adbRepository.executeAdbCommand(adbPath = adbPath, command = "start-server") - .mapSuccess { Unit } + adbRepository.executeAdbCommand( + adbPath = adbPath, + command = "start-server", + target = AdbCommandTargetDomainModel.AllDevices, + ).mapSuccess { Unit } } else { Failure(Throwable("adb path is empty")) }