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.
This commit is contained in:
@@ -92,6 +92,14 @@ type string
|
|||||||
This command will simulate a user typing the given string on the
|
This command will simulate a user typing the given string on the
|
||||||
keyboard by generating the proper KeyEvents.
|
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
|
OTHER NOTES
|
||||||
|
|
||||||
There are some convenience features added to allow running without
|
There are some convenience features added to allow running without
|
||||||
|
|||||||
@@ -369,7 +369,12 @@ public class Monkey {
|
|||||||
mEventSource = new MonkeySourceScript(mScriptFileName, mThrottle);
|
mEventSource = new MonkeySourceScript(mScriptFileName, mThrottle);
|
||||||
mEventSource.setVerbose(mVerbose);
|
mEventSource.setVerbose(mVerbose);
|
||||||
} else if (mServerPort != -1) {
|
} 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;
|
mCount = Integer.MAX_VALUE;
|
||||||
} else {
|
} else {
|
||||||
// random source by default
|
// random source by default
|
||||||
|
|||||||
@@ -359,6 +359,8 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
|||||||
|
|
||||||
// QUIT command
|
// QUIT command
|
||||||
private static final String QUIT = "quit";
|
private static final String QUIT = "quit";
|
||||||
|
// DONE command
|
||||||
|
private static final String DONE = "done";
|
||||||
|
|
||||||
// command response strings
|
// command response strings
|
||||||
private static final String OK = "OK";
|
private static final String OK = "OK";
|
||||||
@@ -398,13 +400,19 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
|||||||
|
|
||||||
private final CommandQueueImpl commandQueue = new CommandQueueImpl();
|
private final CommandQueueImpl commandQueue = new CommandQueueImpl();
|
||||||
|
|
||||||
private final int port;
|
|
||||||
private BufferedReader input;
|
private BufferedReader input;
|
||||||
private PrintWriter output;
|
private PrintWriter output;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
|
|
||||||
public MonkeySourceNetwork(int port) {
|
private ServerSocket serverSocket;
|
||||||
this.port = port;
|
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
|
* @param port the port to listen on
|
||||||
*/
|
*/
|
||||||
private void startServer() throws IOException {
|
private void startServer() throws IOException {
|
||||||
// Only bind this to local host. This means that you can only
|
clientSocket = serverSocket.accept();
|
||||||
// talk to the monkey locally, or though adb port forwarding.
|
|
||||||
ServerSocket server = new ServerSocket(port,
|
|
||||||
0, // default backlog
|
|
||||||
InetAddress.getLocalHost());
|
|
||||||
Socket s = server.accept();
|
|
||||||
// At this point, we have a client connected. Wake the device
|
// At this point, we have a client connected. Wake the device
|
||||||
// up in preparation for doing some commands.
|
// up in preparation for doing some commands.
|
||||||
wake();
|
wake();
|
||||||
|
|
||||||
input = new BufferedReader(new InputStreamReader(s.getInputStream()));
|
input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||||
// auto-flush
|
// 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();
|
String command = input.readLine();
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
Log.d(TAG, "Connection dropped.");
|
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
|
// Do quit checking here
|
||||||
if (QUIT.equals(command)) {
|
if (QUIT.equals(command)) {
|
||||||
// then we're done
|
// then we're done
|
||||||
|
|||||||
Reference in New Issue
Block a user