Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECH: adbserver's backward compatibility was fixed #672

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList()
) : Command(command, arguments)
override val body: String,
) : Command(body)
Original file line number Diff line number Diff line change
@@ -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<String> = emptyList()
) : Command(command, arguments)
) : ComplexCommand(body, arguments)
Original file line number Diff line number Diff line change
@@ -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<String> = emptyList()
) : ComplexCommand(body, arguments)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import java.io.Serializable
/**
* Command to execute by AdbServer
*/
abstract class Command(open val command: String, open val arguments: List<String> = emptyList()) : Serializable
abstract class Command(open val body: String) : Serializable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.kaspersky.adbserver.common.api

abstract class ComplexCommand(override val body: String, open val arguments: List<String> = emptyList()) : Command(body)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +36,7 @@ object AdbTerminal {
* Please first of all call [connect] method to establish a connection
*/
fun executeAdb(command: String, arguments: List<String>): CommandResult = device?.fulfill(
AdbCommand(command, arguments)
ComplexAdbCommand(command, arguments)
) ?: throw IllegalStateException("Please first of all call [connect] method to establish a connection")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<String>

if (command.arguments.isEmpty()) {
adbCommand = "$adbPath ${adbServerPort?.let { "-P $adbServerPort " } ?: ""}-s $deviceName ${command.command}"
adbCommand = getSimpleAdbCommand(command)
adbArguments = emptyList()
} else {
adbCommand = adbPath
Expand All @@ -36,7 +45,7 @@ internal class CommandExecutorImpl(
}
add("-s")
add(deviceName)
add(command.command)
add(command.body)
addAll(command.arguments)
}
}
Expand Down
Binary file modified artifacts/adbserver-desktop.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Loading