-
Notifications
You must be signed in to change notification settings - Fork 159
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
ISSUE-576: Allow complex ADB server commands execution #597
Changes from 12 commits
32984da
8b4ecbb
8ca3a8c
bbbe71c
858bd99
329a5df
3537b68
f3b688a
87390fc
4c78a17
faf482e
d6ac80d
1c609a4
64e67c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ package com.kaspersky.adbserver.commandtypes | |
|
||
import com.kaspersky.adbserver.common.api.Command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also reflect all these cases in tests? I mean testing a single command, a command with arguments and a command with commands in arguments (complex commands with pipes and etc.). |
||
|
||
data class AdbCommand(override val body: String) : Command(body) | ||
data class AdbCommand( | ||
override val command: String, | ||
override val arguments: List<String> = emptyList() | ||
) : Command(command, arguments) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.kaspersky.kaspresso.device.server | ||
|
||
import android.annotation.SuppressLint | ||
|
||
/** | ||
* This is a comfortable wrapper to work with AdbServer repository. | ||
* | ||
|
@@ -20,36 +22,108 @@ interface AdbServer { | |
* | ||
* Required Permissions: INTERNET. | ||
* | ||
* @see <a href="https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md">AdbServer documentation</a> | ||
* @param commands commands to execute. | ||
* @throws AdbServerException if a result status of any command in @param commands is Failed | ||
* @return list of answers of commands' execution | ||
*/ | ||
@SuppressLint("SdCardPath") | ||
@Deprecated("This method doesn't work for the commands with the complex arguments containing " + | ||
"whitespaces (e.g. 'adb pull \"/sdcard/Documents/path_with whitespace to/file.txt\") and doesn't allow commands piping like" + | ||
"adbServer.performCmd(\"bash\", listOf(\"-c\", \"adb shell dumpsys deviceidle | grep mForceIdle\"))" + | ||
"which the AdbServer.performCmd(String, List<String>) does. " + | ||
"For more details, please check out https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md", | ||
ReplaceWith("adbServer.performCmd(*commands, emptyList())") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that it is correct replacement? You put an array ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the best from the worst. If you leave just |
||
) | ||
fun performCmd(vararg commands: String): List<String> | ||
|
||
/** | ||
* Performs shell commands blocking current thread. Allows more control over how arguments are parsed. | ||
matzuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Each list element is used as is. Refer to the https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please unify your comments. Somewhere you write class and method name, somewhere you provide a link. |
||
* | ||
* Please be aware! If any command that is in @param commands failed then AdbServerException will be thrown | ||
* | ||
* Required Permissions: INTERNET. | ||
* | ||
* @see <a href="https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md">AdbServer documentation</a> | ||
* @param commands commands to execute. | ||
* @throws AdbServerException if a result status of any command in @param commands is Failed | ||
* @return list of answers of commands' execution | ||
*/ | ||
fun performCmd(command: String, arguments: List<String>): String | ||
|
||
/** | ||
* Performs adb commands blocking current thread. | ||
* Please be aware! If any command that is in @param commands failed then AdbServerException will be thrown | ||
* | ||
* Required Permissions: INTERNET. | ||
* | ||
* @see <a href="https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md">AdbServer documentation</a> | ||
* @param commands commands to execute. | ||
* @throws AdbServerException if a result status of any command in @param commands is Failed | ||
* @return list of answers of commands' execution | ||
*/ | ||
@SuppressLint("SdCardPath") | ||
@Deprecated("This method doesn't work for the commands with the complex arguments containing " + | ||
"whitespaces (e.g. 'adb pull \"/sdcard/Documents/path_with whitespace to/file.txt\") and doesn't allow commands piping like" + | ||
"adbServer.performCmd(\"bash\", listOf(\"-c\", \"adb shell dumpsys deviceidle | grep mForceIdle\"))" + | ||
"which the AdbServer.performAdb(String, List<String>) does " + | ||
"For more details, please check out https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md", | ||
ReplaceWith("adbServer.performAdb(*commands, emptyList())") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I am not sure about your replacement. |
||
) | ||
fun performAdb(vararg commands: String): List<String> | ||
|
||
/** | ||
* Performs adb commands blocking current thread. Allows more control over how arguments are parsed. | ||
* Each list element is used as is. Refer to the https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html. | ||
* | ||
* Please be aware! If any command that is in @param commands failed then AdbServerException will be thrown | ||
* | ||
* Required Permissions: INTERNET. | ||
* | ||
* @see <a href="https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md">AdbServer documentation</a> | ||
* @param commands commands to execute. | ||
* @throws AdbServerException if a result status of any command in @param commands is Failed | ||
* @return list of answers of commands' execution | ||
*/ | ||
fun performAdb(command: String, arguments: List<String>): String | ||
|
||
/** | ||
* Performs shell commands blocking current thread. | ||
* Please be aware! If any command that is in @param commands failed then AdbServerException will be thrown | ||
* | ||
* Required Permissions: INTERNET. | ||
* | ||
* @see <a href="https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md">AdbServer documentation</a> | ||
* @param commands commands to execute. | ||
* @throws AdbServerException if a result status of any command in @param commands is Failed | ||
* @return list of answers of commands' execution | ||
*/ | ||
@SuppressLint("SdCardPath") | ||
@Deprecated("This method doesn't work for the commands with the complex arguments containing " + | ||
"whitespaces (e.g. 'adb pull \"/sdcard/Documents/path_with whitespace to/file.txt\") and doesn't allow commands piping like" + | ||
"adbServer.performCmd(\"bash\", listOf(\"-c\", \"adb shell dumpsys deviceidle | grep mForceIdle\"))" + | ||
"which the AdbServer.performShell(String, List<String>) does " + | ||
"For more details, please check out https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md", | ||
ReplaceWith("adbServer.performShell(*commands, emptyList())") | ||
) | ||
fun performShell(vararg commands: String): List<String> | ||
|
||
/** | ||
* Performs shell commands blocking current thread. Allows more control over how arguments are parsed. | ||
* Each list element is used as is. Refer to the https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html. | ||
* | ||
* Please be aware! If any command that is in @param commands failed then AdbServerException will be thrown | ||
* | ||
* Required Permissions: INTERNET. | ||
* | ||
* @see <a href="https://github.com/KasperskyLab/Kaspresso/blob/master/docs/Wiki/Executing_adb_commands.en.md">AdbServer documentation</a> | ||
* @param commands commands to execute. | ||
* @throws AdbServerException if a result status of any command in @param commands is Failed | ||
* @return list of answers of commands' execution | ||
*/ | ||
fun performShell(command: String, arguments: List<String>): String | ||
|
||
/** | ||
* Disconnect from AdbServer. | ||
* The method is called by Kaspresso after each test. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General feedback.
I guess we can use
Runtime::exec(String[] cmdarray)
instead ofRuntime::exec(String command)
inCmdCommandPerformer.perform
. Have a look atjava.lang.Runtime
, where both methods call the same method andcommand
param inRuntime::exec(String command)
is parsing into the array of strings.I don't support introducing separate classes like
ComplexAdbCommand
. I think we need to add the new constructors likeCommand(command: String, arguments: List<String>)
and the correspondent methods inAdbTerminal
and etc.I don't support syntaxis like
(command: List<String>)
and(command): String
. It's confusing. Also, the most popular syntaxis in these cases is(command: String, arguments: List<String>)
. Yes, another command is an argument of the main command. Cases likesh -c "adb shell dumpsys deviceidle | grep mForceIdle"
should be described in the documentation and examples.