summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorBill Napier <napier@google.com>2009-08-11 16:36:43 -0700
committerBill Napier <napier@google.com>2009-08-12 09:31:33 -0700
commit9d8557c4b3156672b9177cab9d97701d85363836 (patch)
tree180dda1516ff91189b6359d71aa37d9928621a17 /cmds
parent4bff8ab0e9073ae537e8a6c4ee8240a6698384f8 (diff)
downloadandroid_development-9d8557c4b3156672b9177cab9d97701d85363836.tar.gz
android_development-9d8557c4b3156672b9177cab9d97701d85363836.tar.bz2
android_development-9d8557c4b3156672b9177cab9d97701d85363836.zip
Squashed commit of the following:
commit d36aba1463cf8dca9dea7b4e436a71c6821f341a Author: Bill Napier <napier@google.com> Date: Tue Aug 11 16:36:07 2009 -0700 Change disconnect to be the same as if the user had issued a done command. commit 4ab3ef149e815188105e10febd5a00ee5d0574fc Author: Bill Napier <napier@google.com> Date: Tue Aug 11 16:31:16 2009 -0700 Add "done" command to allow multiple sessions.
Diffstat (limited to 'cmds')
-rw-r--r--cmds/monkey/README.NETWORK.txt8
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/Monkey.java7
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java53
3 files changed, 55 insertions, 13 deletions
diff --git a/cmds/monkey/README.NETWORK.txt b/cmds/monkey/README.NETWORK.txt
index b80cea9f7..51b56c87d 100644
--- a/cmds/monkey/README.NETWORK.txt
+++ b/cmds/monkey/README.NETWORK.txt
@@ -92,6 +92,14 @@ type string
This command will simulate a user typing the given string on the
keyboard by generating the proper KeyEvents.
+quit
+
+Fully quit the monkey and accept no new sessions.
+
+done
+
+Close the current session and allow a new session to connect
+
OTHER NOTES
There are some convenience features added to allow running without
diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
index 6b10147a6..709a70c1a 100644
--- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java
+++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
@@ -369,7 +369,12 @@ public class Monkey {
mEventSource = new MonkeySourceScript(mScriptFileName, mThrottle);
mEventSource.setVerbose(mVerbose);
} else if (mServerPort != -1) {
- mEventSource = new MonkeySourceNetwork(mServerPort);
+ try {
+ mEventSource = new MonkeySourceNetwork(mServerPort);
+ } catch (IOException e) {
+ System.out.println("Error binding to network socket.");
+ return -5;
+ }
mCount = Integer.MAX_VALUE;
} else {
// random source by default
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java
index 5937f09c1..7a2bccd30 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java
@@ -359,6 +359,8 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
// QUIT command
private static final String QUIT = "quit";
+ // DONE command
+ private static final String DONE = "done";
// command response strings
private static final String OK = "OK";
@@ -398,13 +400,19 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
private final CommandQueueImpl commandQueue = new CommandQueueImpl();
- private final int port;
private BufferedReader input;
private PrintWriter output;
private boolean started = false;
- public MonkeySourceNetwork(int port) {
- this.port = port;
+ private ServerSocket serverSocket;
+ private Socket clientSocket;
+
+ public MonkeySourceNetwork(int port) throws IOException {
+ // Only bind this to local host. This means that you can only
+ // talk to the monkey locally, or though adb port forwarding.
+ serverSocket = new ServerSocket(port,
+ 0, // default backlog
+ InetAddress.getLocalHost());
}
/**
@@ -415,19 +423,24 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
* @param port the port to listen on
*/
private void startServer() throws IOException {
- // Only bind this to local host. This means that you can only
- // talk to the monkey locally, or though adb port forwarding.
- ServerSocket server = new ServerSocket(port,
- 0, // default backlog
- InetAddress.getLocalHost());
- Socket s = server.accept();
+ clientSocket = serverSocket.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()));
+ input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// auto-flush
- output = new PrintWriter(s.getOutputStream(), true);
+ output = new PrintWriter(clientSocket.getOutputStream(), true);
+ }
+
+ /**
+ * Stop the server from running so it can reconnect a new client.
+ */
+ private void stopServer() throws IOException {
+ clientSocket.close();
+ input.close();
+ output.close();
+ started = false;
}
/**
@@ -529,8 +542,24 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
String command = input.readLine();
if (command == null) {
Log.d(TAG, "Connection dropped.");
- return null;
+ // Treat this exactly the same as if the user had
+ // ended the session cleanly with a done commant.
+ command = DONE;
}
+
+ if (DONE.equals(command)) {
+ // stop the server so it can accept new connections
+ try {
+ stopServer();
+ } catch (IOException e) {
+ Log.e(TAG, "Got IOException shutting down!", e);
+ return null;
+ }
+ // return a noop event so we keep executing the main
+ // loop
+ return new MonkeyNoopEvent();
+ }
+
// Do quit checking here
if (QUIT.equals(command)) {
// then we're done