diff --git a/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/AdbCommand.kt b/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/AdbCommand.kt index 0a6d3a3ed..a402a7b3f 100644 --- a/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/AdbCommand.kt +++ b/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/AdbCommand.kt @@ -2,7 +2,9 @@ package com.kaspersky.adbserver.commandtypes import com.kaspersky.adbserver.common.api.Command +/** + * Command for backward compatibility with old version of adb-server + */ data class AdbCommand( - override val command: String, - override val arguments: List = emptyList() -) : Command(command, arguments) + override val body: String, +) : Command(body) diff --git a/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/CmdCommand.kt b/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/CmdCommand.kt index b490a1e73..e748f75ab 100644 --- a/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/CmdCommand.kt +++ b/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/CmdCommand.kt @@ -1,8 +1,8 @@ package com.kaspersky.adbserver.commandtypes -import com.kaspersky.adbserver.common.api.Command +import com.kaspersky.adbserver.common.api.ComplexCommand data class CmdCommand( - override val command: String, + override val body: String, override val arguments: List = emptyList() -) : Command(command, arguments) +) : ComplexCommand(body, arguments) diff --git a/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/ComplexAdbCommand.kt b/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/ComplexAdbCommand.kt new file mode 100644 index 000000000..658b1137f --- /dev/null +++ b/adb-server/adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/ComplexAdbCommand.kt @@ -0,0 +1,8 @@ +package com.kaspersky.adbserver.commandtypes + +import com.kaspersky.adbserver.common.api.ComplexCommand + +data class ComplexAdbCommand( + override val body: String, + override val arguments: List = emptyList() +) : ComplexCommand(body, arguments) diff --git a/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/Command.kt b/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/Command.kt index d70103224..96e4b738d 100644 --- a/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/Command.kt +++ b/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/Command.kt @@ -5,4 +5,4 @@ import java.io.Serializable /** * Command to execute by AdbServer */ -abstract class Command(open val command: String, open val arguments: List = emptyList()) : Serializable +abstract class Command(open val body: String) : Serializable diff --git a/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/ComplexCommand.kt b/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/ComplexCommand.kt new file mode 100644 index 000000000..e9e4bce29 --- /dev/null +++ b/adb-server/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/ComplexCommand.kt @@ -0,0 +1,3 @@ +package com.kaspersky.adbserver.common.api + +abstract class ComplexCommand(override val body: String, open val arguments: List = emptyList()) : Command(body) diff --git a/adb-server/adb-server-device/src/main/java/com/kaspersky/adbserver/device/AdbTerminal.kt b/adb-server/adb-server-device/src/main/java/com/kaspersky/adbserver/device/AdbTerminal.kt index 8f6a86901..8bffa11b0 100644 --- a/adb-server/adb-server-device/src/main/java/com/kaspersky/adbserver/device/AdbTerminal.kt +++ b/adb-server/adb-server-device/src/main/java/com/kaspersky/adbserver/device/AdbTerminal.kt @@ -2,6 +2,7 @@ package com.kaspersky.adbserver.device import com.kaspersky.adbserver.commandtypes.AdbCommand import com.kaspersky.adbserver.commandtypes.CmdCommand +import com.kaspersky.adbserver.commandtypes.ComplexAdbCommand import com.kaspersky.adbserver.common.api.CommandResult import com.kaspersky.adbserver.common.log.LoggerFactory import com.kaspersky.adbserver.common.log.logger.LogLevel @@ -35,7 +36,7 @@ object AdbTerminal { * Please first of all call [connect] method to establish a connection */ fun executeAdb(command: String, arguments: List): CommandResult = device?.fulfill( - AdbCommand(command, arguments) + ComplexAdbCommand(command, arguments) ) ?: throw IllegalStateException("Please first of all call [connect] method to establish a connection") /** diff --git a/adb-server/adbserver-desktop/src/main/java/com/kaspersky/adbserver/desktop/CommandExecutorImpl.kt b/adb-server/adbserver-desktop/src/main/java/com/kaspersky/adbserver/desktop/CommandExecutorImpl.kt index 7aceb84e8..bf3d8d0e8 100644 --- a/adb-server/adbserver-desktop/src/main/java/com/kaspersky/adbserver/desktop/CommandExecutorImpl.kt +++ b/adb-server/adbserver-desktop/src/main/java/com/kaspersky/adbserver/desktop/CommandExecutorImpl.kt @@ -5,6 +5,7 @@ import com.kaspersky.adbserver.common.api.CommandExecutor import com.kaspersky.adbserver.common.api.CommandResult import com.kaspersky.adbserver.commandtypes.AdbCommand import com.kaspersky.adbserver.commandtypes.CmdCommand +import com.kaspersky.adbserver.commandtypes.ComplexAdbCommand import com.kaspersky.adbserver.common.log.logger.Logger import java.lang.UnsupportedOperationException @@ -16,16 +17,24 @@ internal class CommandExecutorImpl( private val adbPath: String ) : CommandExecutor { + private fun getSimpleAdbCommand(command: Command): String = "$adbPath ${adbServerPort?.let { "-P $adbServerPort " } ?: ""}-s $deviceName ${command.body}" + override fun execute(command: Command): CommandResult { return when (command) { - is CmdCommand -> cmdCommandPerformer.perform(command.command, command.arguments) + is CmdCommand -> cmdCommandPerformer.perform(command.body, command.arguments) is AdbCommand -> { + val adbCommand = getSimpleAdbCommand(command) + logger.d("The created adbCommand=$adbCommand") + cmdCommandPerformer.perform(adbCommand, emptyList()) + } + + is ComplexAdbCommand -> { val adbCommand: String val adbArguments: List if (command.arguments.isEmpty()) { - adbCommand = "$adbPath ${adbServerPort?.let { "-P $adbServerPort " } ?: ""}-s $deviceName ${command.command}" + adbCommand = getSimpleAdbCommand(command) adbArguments = emptyList() } else { adbCommand = adbPath @@ -36,7 +45,7 @@ internal class CommandExecutorImpl( } add("-s") add(deviceName) - add(command.command) + add(command.body) addAll(command.arguments) } } diff --git a/artifacts/adbserver-desktop.jar b/artifacts/adbserver-desktop.jar index a38166f8a..edf3fe708 100644 Binary files a/artifacts/adbserver-desktop.jar and b/artifacts/adbserver-desktop.jar differ diff --git a/samples/kaspresso-sample/src/androidTest/kotlin/com/kaspersky/kaspressample/adb_server_tests/AdbServerTest.kt b/samples/kaspresso-sample/src/androidTest/kotlin/com/kaspersky/kaspressample/adb_server_tests/AdbServerTest.kt index fc1cf4fac..730b52ccf 100644 --- a/samples/kaspresso-sample/src/androidTest/kotlin/com/kaspersky/kaspressample/adb_server_tests/AdbServerTest.kt +++ b/samples/kaspresso-sample/src/androidTest/kotlin/com/kaspersky/kaspressample/adb_server_tests/AdbServerTest.kt @@ -21,6 +21,12 @@ class AdbServerTest : TestCase() { @Test fun singleCommandTest() = run { + val devices = adbServer.performAdb("devices") + assert(devices.isNotEmpty()) + } + + @Test + fun singleComplexCommandTest() = run { val devices = adbServer.performAdb("devices", arguments = emptyList()) assert(devices.isNotEmpty()) }