summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorYu Shan Emily Lau <yslau@google.com>2010-08-17 20:00:07 -0700
committerYu Shan Emily Lau <yslau@google.com>2010-08-19 11:03:34 -0700
commit4fbc8db8911c2a97a433dc2b1ef995a6217406c6 (patch)
tree92ee15c20c11a9c6a7a2b26721cc9e19ed2f747e /cmds
parent8fc778984cd0b737df102fca14be7c1815505b80 (diff)
downloadandroid_development-4fbc8db8911c2a97a433dc2b1ef995a6217406c6.tar.gz
android_development-4fbc8db8911c2a97a433dc2b1ef995a6217406c6.tar.bz2
android_development-4fbc8db8911c2a97a433dc2b1ef995a6217406c6.zip
Add the monkey event which allows the scripted monkey to execute the shell command.
Change-Id: Id5548fc42fc5c7bee6879fffc580e134a75572ab
Diffstat (limited to 'cmds')
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyCommandEvent.java51
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java9
2 files changed, 60 insertions, 0 deletions
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyCommandEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyCommandEvent.java
new file mode 100644
index 000000000..2122cce19
--- /dev/null
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyCommandEvent.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.commands.monkey;
+
+import android.app.IActivityManager;
+import android.view.IWindowManager;
+import android.os.Build;
+
+
+/**
+ * Events for running the shell command.
+ */
+public class MonkeyCommandEvent extends MonkeyEvent {
+
+ private String mCmd;
+
+ public MonkeyCommandEvent(String cmd) {
+ super(EVENT_TYPE_ACTIVITY);
+ mCmd = cmd;
+ }
+
+ @Override
+ public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
+ if (mCmd != null) {
+ //Execute the shell command
+ try {
+ java.lang.Process p = Runtime.getRuntime().exec(mCmd);
+ int status = p.waitFor();
+ System.err.println("// Shell command " + mCmd + " status was " + status);
+ } catch (Exception e) {
+ System.err.println("// Exception from " + mCmd + ":");
+ System.err.println(e.toString());
+ }
+ }
+ return MonkeyEvent.INJECT_SUCCESS;
+ }
+}
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java
index a1d1f2949..09d247dcf 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java
@@ -102,6 +102,8 @@ public class MonkeySourceScript implements MonkeyEventSource {
private static final String EVENT_KEYWORD_WRITEPOWERLOG = "WriteLog";
+ private static final String EVENT_KEYWORD_RUNCMD = "RunCmd";
+
// a line at the end of the header
private static final String STARTING_DATA_LINE = "start data >>";
@@ -355,6 +357,13 @@ public class MonkeySourceScript implements MonkeyEventSource {
MonkeyPowerEvent e = new MonkeyPowerEvent();
mQ.addLast(e);
}
+
+ //Run the shell command
+ if (s.indexOf(EVENT_KEYWORD_RUNCMD) >= 0 && args.length == 1) {
+ String cmd = args[0];
+ MonkeyCommandEvent e = new MonkeyCommandEvent(cmd);
+ mQ.addLast(e);
+ }
}
/**