Merge "Add the monkey event which allows the scripted monkey to execute the shell command." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
b409cf9ca1
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,6 +102,8 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
|
|
||||||
private static final String EVENT_KEYWORD_WRITEPOWERLOG = "WriteLog";
|
private static final String EVENT_KEYWORD_WRITEPOWERLOG = "WriteLog";
|
||||||
|
|
||||||
|
private static final String EVENT_KEYWORD_RUNCMD = "RunCmd";
|
||||||
|
|
||||||
// a line at the end of the header
|
// a line at the end of the header
|
||||||
private static final String STARTING_DATA_LINE = "start data >>";
|
private static final String STARTING_DATA_LINE = "start data >>";
|
||||||
|
|
||||||
@@ -355,6 +357,13 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
MonkeyPowerEvent e = new MonkeyPowerEvent();
|
MonkeyPowerEvent e = new MonkeyPowerEvent();
|
||||||
mQ.addLast(e);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user