aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2013-02-21 20:53:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-02-21 20:53:48 +0000
commit61356903af3519f6cec928c139abc2df2027f7dd (patch)
tree8364aede8ef4d6b2209ba7c01a4e692da67e1f2f
parenta6700cafcda4193b5447068c05e639a131439c4b (diff)
parent8dd0bc70cb283db5d38bfaa15f9cbb3948f02324 (diff)
downloadsdk-61356903af3519f6cec928c139abc2df2027f7dd.zip
sdk-61356903af3519f6cec928c139abc2df2027f7dd.tar.gz
sdk-61356903af3519f6cec928c139abc2df2027f7dd.tar.bz2
Merge "Extended the MonkeyRunner shell method with timeout arg."
-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 200c69e..af09efe 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 41e58f9..5dc7e7b 100644
--- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
+++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java
@@ -209,15 +209,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.",