Merge "Add the new option for the device sleep time. This is only for the scripted monkey." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
ea7d6e8e65
@@ -176,6 +176,9 @@ public class Monkey {
|
|||||||
/** The delay between user actions. This is for the scripted monkey. **/
|
/** The delay between user actions. This is for the scripted monkey. **/
|
||||||
long mProfileWaitTime = 5000;
|
long mProfileWaitTime = 5000;
|
||||||
|
|
||||||
|
/** Device idle time. This is for the scripted monkey. **/
|
||||||
|
long mDeviceSleepTime = 30000;
|
||||||
|
|
||||||
/** a filename to the setup script (if any) */
|
/** a filename to the setup script (if any) */
|
||||||
private String mSetupFileName = null;
|
private String mSetupFileName = null;
|
||||||
|
|
||||||
@@ -462,18 +465,18 @@ public class Monkey {
|
|||||||
if (mScriptFileNames != null && mScriptFileNames.size() == 1) {
|
if (mScriptFileNames != null && mScriptFileNames.size() == 1) {
|
||||||
// script mode, ignore other options
|
// script mode, ignore other options
|
||||||
mEventSource = new MonkeySourceScript(mRandom, mScriptFileNames.get(0), mThrottle,
|
mEventSource = new MonkeySourceScript(mRandom, mScriptFileNames.get(0), mThrottle,
|
||||||
mRandomizeThrottle, mProfileWaitTime);
|
mRandomizeThrottle, mProfileWaitTime, mDeviceSleepTime);
|
||||||
mEventSource.setVerbose(mVerbose);
|
mEventSource.setVerbose(mVerbose);
|
||||||
|
|
||||||
mCountEvents = false;
|
mCountEvents = false;
|
||||||
} else if (mScriptFileNames != null && mScriptFileNames.size() > 1) {
|
} else if (mScriptFileNames != null && mScriptFileNames.size() > 1) {
|
||||||
if (mSetupFileName != null) {
|
if (mSetupFileName != null) {
|
||||||
mEventSource = new MonkeySourceRandomScript(mSetupFileName, mScriptFileNames,
|
mEventSource = new MonkeySourceRandomScript(mSetupFileName, mScriptFileNames,
|
||||||
mThrottle, mRandomizeThrottle, mRandom, mProfileWaitTime);
|
mThrottle, mRandomizeThrottle, mRandom, mProfileWaitTime, mDeviceSleepTime);
|
||||||
mCount++;
|
mCount++;
|
||||||
} else {
|
} else {
|
||||||
mEventSource = new MonkeySourceRandomScript(mScriptFileNames, mThrottle,
|
mEventSource = new MonkeySourceRandomScript(mScriptFileNames, mThrottle,
|
||||||
mRandomizeThrottle, mRandom, mProfileWaitTime);
|
mRandomizeThrottle, mRandom, mProfileWaitTime, mDeviceSleepTime);
|
||||||
}
|
}
|
||||||
mEventSource.setVerbose(mVerbose);
|
mEventSource.setVerbose(mVerbose);
|
||||||
mCountEvents = false;
|
mCountEvents = false;
|
||||||
@@ -659,6 +662,9 @@ public class Monkey {
|
|||||||
} else if (opt.equals("--profile-wait")) {
|
} else if (opt.equals("--profile-wait")) {
|
||||||
mProfileWaitTime = nextOptionLong("Profile delay" +
|
mProfileWaitTime = nextOptionLong("Profile delay" +
|
||||||
" (in milliseconds) to wait between user action");
|
" (in milliseconds) to wait between user action");
|
||||||
|
} else if (opt.equals("--device-sleep-time")) {
|
||||||
|
mDeviceSleepTime = nextOptionLong("Device sleep time" +
|
||||||
|
"(in milliseconds)");
|
||||||
} else if (opt.equals("-h")) {
|
} else if (opt.equals("-h")) {
|
||||||
showUsage();
|
showUsage();
|
||||||
return false;
|
return false;
|
||||||
@@ -1130,6 +1136,7 @@ public class Monkey {
|
|||||||
usage.append(" [-s SEED] [-v [-v] ...]\n");
|
usage.append(" [-s SEED] [-v [-v] ...]\n");
|
||||||
usage.append(" [--throttle MILLISEC] [--randomize-throttle]\n");
|
usage.append(" [--throttle MILLISEC] [--randomize-throttle]\n");
|
||||||
usage.append(" [--profile-wait MILLISEC]\n");
|
usage.append(" [--profile-wait MILLISEC]\n");
|
||||||
|
usage.append(" [--device-sleep-time MILLISEC]\n");
|
||||||
usage.append(" COUNT\n");
|
usage.append(" COUNT\n");
|
||||||
System.err.println(usage.toString());
|
System.err.println(usage.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class MonkeyActivityEvent extends MonkeyEvent {
|
public class MonkeyActivityEvent extends MonkeyEvent {
|
||||||
private ComponentName mApp;
|
private ComponentName mApp;
|
||||||
String mAlarmTime;
|
long mAlarmTime = 0;
|
||||||
|
|
||||||
public MonkeyActivityEvent(ComponentName app) {
|
public MonkeyActivityEvent(ComponentName app) {
|
||||||
super(EVENT_TYPE_ACTIVITY);
|
super(EVENT_TYPE_ACTIVITY);
|
||||||
mApp = app;
|
mApp = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MonkeyActivityEvent(ComponentName app, String arg) {
|
public MonkeyActivityEvent(ComponentName app, long arg) {
|
||||||
super(EVENT_TYPE_ACTIVITY);
|
super(EVENT_TYPE_ACTIVITY);
|
||||||
mApp = app;
|
mApp = app;
|
||||||
mAlarmTime = arg;
|
mAlarmTime = arg;
|
||||||
@@ -60,9 +60,9 @@ public class MonkeyActivityEvent extends MonkeyEvent {
|
|||||||
System.out.println(":Switch: " + intent.toURI());
|
System.out.println(":Switch: " + intent.toURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mAlarmTime != null){
|
if (mAlarmTime != 0){
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("alarmTime", mAlarmTime);
|
args.putLong("alarmTime", mAlarmTime);
|
||||||
intent.putExtras(args);
|
intent.putExtras(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,16 +48,17 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
|||||||
* @param random The random number generator.
|
* @param random The random number generator.
|
||||||
*/
|
*/
|
||||||
public MonkeySourceRandomScript(String setupFileName, ArrayList<String> scriptFileNames,
|
public MonkeySourceRandomScript(String setupFileName, ArrayList<String> scriptFileNames,
|
||||||
long throttle, boolean randomizeThrottle, Random random, long profileWaitTime) {
|
long throttle, boolean randomizeThrottle, Random random, long profileWaitTime,
|
||||||
|
long deviceSleepTime) {
|
||||||
if (setupFileName != null) {
|
if (setupFileName != null) {
|
||||||
mSetupSource = new MonkeySourceScript(random, setupFileName, throttle,
|
mSetupSource = new MonkeySourceScript(random, setupFileName, throttle,
|
||||||
randomizeThrottle, profileWaitTime);
|
randomizeThrottle, profileWaitTime, deviceSleepTime);
|
||||||
mCurrentSource = mSetupSource;
|
mCurrentSource = mSetupSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String fileName: scriptFileNames) {
|
for (String fileName: scriptFileNames) {
|
||||||
mScriptSources.add(new MonkeySourceScript(random, fileName, throttle,
|
mScriptSources.add(new MonkeySourceScript(random, fileName, throttle,
|
||||||
randomizeThrottle, profileWaitTime));
|
randomizeThrottle, profileWaitTime, deviceSleepTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
mRandom = random;
|
mRandom = random;
|
||||||
@@ -72,8 +73,9 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
|||||||
* @param random The random number generator.
|
* @param random The random number generator.
|
||||||
*/
|
*/
|
||||||
public MonkeySourceRandomScript(ArrayList<String> scriptFileNames, long throttle,
|
public MonkeySourceRandomScript(ArrayList<String> scriptFileNames, long throttle,
|
||||||
boolean randomizeThrottle, Random random, long profileWaitTime) {
|
boolean randomizeThrottle, Random random, long profileWaitTime, long deviceSleepTime) {
|
||||||
this(null, scriptFileNames, throttle, randomizeThrottle, random, profileWaitTime);
|
this(null, scriptFileNames, throttle, randomizeThrottle, random, profileWaitTime,
|
||||||
|
deviceSleepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
|
|
||||||
private static final String EVENT_KEYWORD_PROFILE_WAIT = "ProfileWait";
|
private static final String EVENT_KEYWORD_PROFILE_WAIT = "ProfileWait";
|
||||||
|
|
||||||
|
private static final String EVENT_KEYWORD_DEVICE_WAKEUP = "DeviceWakeUp";
|
||||||
|
|
||||||
// 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 >>";
|
||||||
|
|
||||||
@@ -117,6 +119,8 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
|
|
||||||
private long mProfileWaitTime = 5000; //Wait time for each user profile
|
private long mProfileWaitTime = 5000; //Wait time for each user profile
|
||||||
|
|
||||||
|
private long mDeviceSleepTime = 30000; //Device sleep time
|
||||||
|
|
||||||
FileInputStream mFStream;
|
FileInputStream mFStream;
|
||||||
|
|
||||||
DataInputStream mInputStream;
|
DataInputStream mInputStream;
|
||||||
@@ -130,10 +134,11 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
* @param throttle The amount of time in ms to sleep between events.
|
* @param throttle The amount of time in ms to sleep between events.
|
||||||
*/
|
*/
|
||||||
public MonkeySourceScript(Random random, String filename, long throttle,
|
public MonkeySourceScript(Random random, String filename, long throttle,
|
||||||
boolean randomizeThrottle, long profileWaitTime) {
|
boolean randomizeThrottle, long profileWaitTime, long deviceSleepTime) {
|
||||||
mScriptFileName = filename;
|
mScriptFileName = filename;
|
||||||
mQ = new MonkeyEventQueue(random, throttle, randomizeThrottle);
|
mQ = new MonkeyEventQueue(random, throttle, randomizeThrottle);
|
||||||
mProfileWaitTime = profileWaitTime;
|
mProfileWaitTime = profileWaitTime;
|
||||||
|
mDeviceSleepTime = deviceSleepTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -317,12 +322,17 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
if (s.indexOf(EVENT_KEYWORD_ACTIVITY) >= 0 && args.length >= 2) {
|
if (s.indexOf(EVENT_KEYWORD_ACTIVITY) >= 0 && args.length >= 2) {
|
||||||
String pkg_name = args[0];
|
String pkg_name = args[0];
|
||||||
String cl_name = args[1];
|
String cl_name = args[1];
|
||||||
String alarmTime = null;
|
long alarmTime = 0;
|
||||||
|
|
||||||
ComponentName mApp = new ComponentName(pkg_name, cl_name);
|
ComponentName mApp = new ComponentName(pkg_name, cl_name);
|
||||||
|
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
alarmTime = args[2];
|
try {
|
||||||
|
alarmTime = Long.parseLong(args[2]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("// " + e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
@@ -335,6 +345,23 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Handle the device wake up event
|
||||||
|
if (s.indexOf(EVENT_KEYWORD_DEVICE_WAKEUP) >= 0){
|
||||||
|
String pkg_name = "com.google.android.powerutil";
|
||||||
|
String cl_name = "com.google.android.powerutil.WakeUpScreen";
|
||||||
|
long deviceSleepTime = mDeviceSleepTime;
|
||||||
|
|
||||||
|
ComponentName mApp = new ComponentName(pkg_name, cl_name);
|
||||||
|
MonkeyActivityEvent e1 = new MonkeyActivityEvent(mApp, deviceSleepTime);
|
||||||
|
mQ.addLast(e1);
|
||||||
|
|
||||||
|
//Add the wait event after the device sleep event so that the monkey
|
||||||
|
//can continue after the device wake up.
|
||||||
|
MonkeyWaitEvent e2 = new MonkeyWaitEvent(deviceSleepTime + 3000);
|
||||||
|
mQ.addLast(e2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle launch instrumentation events
|
// Handle launch instrumentation events
|
||||||
if (s.indexOf(EVENT_KEYWORD_INSTRUMENTATION) >= 0 && args.length == 2) {
|
if (s.indexOf(EVENT_KEYWORD_INSTRUMENTATION) >= 0 && args.length == 2) {
|
||||||
String test_name = args[0];
|
String test_name = args[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user