summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorBill Napier <napier@google.com>2009-08-10 13:22:32 -0700
committerBill Napier <napier@google.com>2009-08-10 13:27:32 -0700
commitad904291499650e3d3aadc0aef617e06d71d3672 (patch)
treeb571bbaa4d48891ec2d6fe3812e3b59e73634be3 /cmds
parentd2057e13d3525ad6293d341f84bdafc2125f3305 (diff)
downloadandroid_development-ad904291499650e3d3aadc0aef617e06d71d3672.tar.gz
android_development-ad904291499650e3d3aadc0aef617e06d71d3672.tar.bz2
android_development-ad904291499650e3d3aadc0aef617e06d71d3672.zip
Add "wake" command to wake device up. Run wake command at first connection.
Diffstat (limited to 'cmds')
-rw-r--r--cmds/monkey/README.NETWORK.txt4
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java25
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyNoopEvent.java42
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java40
4 files changed, 99 insertions, 12 deletions
diff --git a/cmds/monkey/README.NETWORK.txt b/cmds/monkey/README.NETWORK.txt
index f3f69d440..3ec6298f0 100644
--- a/cmds/monkey/README.NETWORK.txt
+++ b/cmds/monkey/README.NETWORK.txt
@@ -73,6 +73,10 @@ flip [open|close]
This simulates the opening or closing the keyboard (like on dream).
+wake
+
+This command will wake the device up from sleep and allow user input.
+
OTHER NOTES
There are some convenience features added to allow running without
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java
index d926be8e4..2783dde21 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java
@@ -22,7 +22,7 @@ import android.view.IWindowManager;
/**
* abstract class for monkey event
*/
-public abstract class MonkeyEvent {
+public abstract class MonkeyEvent {
protected int eventType;
public static final int EVENT_TYPE_KEY = 0;
public static final int EVENT_TYPE_POINTER = 1;
@@ -30,41 +30,42 @@ public abstract class MonkeyEvent {
public static final int EVENT_TYPE_ACTIVITY = 3;
public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip
public static final int EVENT_TYPE_THROTTLE = 5;
-
+ public static final int EVENT_TYPE_NOOP = 6;
+
public static final int INJECT_SUCCESS = 1;
public static final int INJECT_FAIL = 0;
// error code for remote exception during injection
- public static final int INJECT_ERROR_REMOTE_EXCEPTION = -1;
+ public static final int INJECT_ERROR_REMOTE_EXCEPTION = -1;
// error code for security exception during injection
public static final int INJECT_ERROR_SECURITY_EXCEPTION = -2;
-
+
public MonkeyEvent(int type) {
eventType = type;
}
-
- /**
+
+ /**
* @return event type
- */
+ */
public int getEventType() {
return eventType;
}
-
+
/**
* @return true if it is safe to throttle after this event, and false otherwise.
*/
public boolean isThrottlable() {
return true;
}
-
-
+
+
/**
* a method for injecting event
* @param iwm wires to current window manager
* @param iam wires to current activity manager
- * @param verbose a log switch
+ * @param verbose a log switch
* @return INJECT_SUCCESS if it goes through, and INJECT_FAIL if it fails
* in the case of exceptions, return its corresponding error code
*/
- public abstract int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose);
+ public abstract int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose);
}
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyNoopEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyNoopEvent.java
new file mode 100644
index 000000000..ea9273576
--- /dev/null
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyNoopEvent.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 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 java.util.List;
+
+import android.app.IActivityManager;
+import android.view.IWindowManager;
+
+
+/**
+ * monkey noop event (don't do anything).
+ */
+public class MonkeyNoopEvent extends MonkeyEvent {
+
+ public MonkeyNoopEvent() {
+ super(MonkeyEvent.EVENT_TYPE_NOOP);
+ }
+
+ @Override
+ public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
+ // No real work to do
+ if (verbose > 1) {
+ System.out.println("NOOP");
+ }
+ return MonkeyEvent.INJECT_SUCCESS;
+ }
+}
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java
index de784d0ae..b444dd340 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java
@@ -15,6 +15,11 @@
*/
package com.android.commands.monkey;
+import android.content.Context;
+import android.os.IPowerManager;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -203,6 +208,36 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
}
}
+ /**
+ * Command to wake the device up
+ */
+ private static class WakeCommand implements MonkeyCommand {
+ // wake
+ public MonkeyEvent translateCommand(List<String> command) {
+ if (wake()) {
+ return null;
+ }
+ return new MonkeyNoopEvent();
+ }
+ }
+
+ /**
+ * Force the device to wake up.
+ *
+ * @return true if woken up OK.
+ */
+ private static final boolean wake() {
+ IPowerManager pm =
+ IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
+ try {
+ pm.userActivityWithForce(SystemClock.uptimeMillis(), true, true);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Got remote exception", e);
+ return false;
+ }
+ return true;
+ }
+
// This maps from command names to command implementations.
private static final Map<String, MonkeyCommand> COMMAND_MAP = new HashMap<String, MonkeyCommand>();
@@ -213,6 +248,7 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
COMMAND_MAP.put("trackball", new TrackballCommand());
COMMAND_MAP.put("key", new KeyCommand());
COMMAND_MAP.put("sleep", new SleepCommand());
+ COMMAND_MAP.put("wake", new WakeCommand());
}
// QUIT command
@@ -246,6 +282,10 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
0, // default backlog
InetAddress.getLocalHost());
Socket s = server.accept();
+ // At this point, we have a client connected. Wake the device
+ // up in preparation for doing some commands.
+ wake();
+
input = new BufferedReader(new InputStreamReader(s.getInputStream()));
// auto-flush
output = new PrintWriter(s.getOutputStream(), true);