aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpzoli <pzoli>2013-01-23 20:25:44 +0100
committerpzoli <pzatya@gmail.com>2013-02-21 21:45:26 +0100
commit8dd0bc70cb283db5d38bfaa15f9cbb3948f02324 (patch)
tree8eb21029de0ba62ec5da9ab184625f63116a8cf9
parent8f05484bde79afb980283512f85bbbe6cce91200 (diff)
downloadsdk-8dd0bc70cb283db5d38bfaa15f9cbb3948f02324.zip
sdk-8dd0bc70cb283db5d38bfaa15f9cbb3948f02324.tar.gz
sdk-8dd0bc70cb283db5d38bfaa15f9cbb3948f02324.tar.bz2
Extended the MonkeyRunner shell method with timeout arg.
In python via MonkeyRunner it is possible execute shell commands but the running time was reduced to 5 seconds. This patch adds an extra argument for the "shell" method. It decides the maximum amount of time during which the command is allowed to not output any response. A value of 0 means that the method will wait forever. This extra arg is optionally. So the original function works without any changes. Change-Id: I1a6d9b37e1846715342b252b2a2a346c2309a08f Signed-off-by: Zoltán Papp <pzatya@gmail.com>
-rw-r--r--chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java9
-rw-r--r--chimpchat/src/com/android/chimpchat/core/IChimpDevice.java11
-rw-r--r--monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java15
3 files changed, 30 insertions, 5 deletions
diff --git a/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java b/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java
index 7c4b62a..dadb017 100644
--- a/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java
+++ b/chimpchat/src/com/android/chimpchat/adb/AdbChimpDevice.java
@@ -264,9 +264,16 @@ public class AdbChimpDevice implements IChimpDevice {
@Override
public String shell(String cmd) {
+ // 5000 is the default timeout from the ddmlib.
+ // This timeout arg is needed to the backwards compatibility.
+ return shell(cmd, 5000);
+ }
+
+ @Override
+ public String shell(String cmd, int timeout) {
CommandOutputCapture capture = new CommandOutputCapture();
try {
- device.executeShellCommand(cmd, capture);
+ device.executeShellCommand(cmd, capture, timeout);
} catch (TimeoutException e) {
LOG.log(Level.SEVERE, "Error executing command: " + cmd, e);
return null;
diff --git a/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java b/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java
index 14b58a7..60cfa76 100644
--- a/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java
+++ b/chimpchat/src/com/android/chimpchat/core/IChimpDevice.java
@@ -131,12 +131,23 @@ public interface IChimpDevice {
/**
* Execute a shell command.
*
+ * Will timeout if there is no ouput for 5 secounds.
+ *
* @param cmd the command to execute
* @return the output of the command
*/
String shell(String cmd);
/**
+ * Execute a shell command.
+ *
+ * @param cmd the command to execute
+ * @param timeout maximum time to output response
+ * @return the output of the command
+ */
+ String shell(String cmd, int timeout);
+
+ /**
* Install a given package.
*
* @param path the path to the installation package
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
index e60d12e..894408c 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
@@ -206,15 +206,22 @@ public class MonkeyDevice extends PyObject implements ClassDictInit {
}
@MonkeyRunnerExported(doc = "Executes an adb shell command and returns the result, if any.",
- args = { "cmd"},
- argDocs = { "The adb shell command to execute." },
+ args = { "cmd", "timeout"},
+ argDocs = { "The adb shell command to execute.",
+ "This arg is optional. It specifies the maximum amount of time during which the" +
+ "command can go without any output. A value of 0 means the method" +
+ "will wait forever. The unit of the timeout is millisecond"},
returns = "The output from the command.")
public String shell(PyObject[] args, String[] kws) {
ArgParser ap = JythonUtils.createArgParser(args, kws);
Preconditions.checkNotNull(ap);
-
String cmd = ap.getString(0);
- return impl.shell(cmd);
+
+ if (args.length == 2) {
+ return impl.shell(cmd, ap.getInt(1));
+ } else {
+ return impl.shell(cmd);
+ }
}
@MonkeyRunnerExported(doc = "Reboots the specified device into a specified bootloader.",