private static final long LAUNCH_TIMEOUT_MS = 10000;
private static final long NO_DATA_TIMEOUT_MS = 1000;
private static final long NO_ACTIVITY_SLEEP_MS = 100;
+ private static final long REMOTE_DEAD_SLEEP_MS = 100;
private String m_cmdLine;
private String m_logFileName;
parser.init(this, m_logFileName, m_logData);
+ // parse until tester dies
+ {
+ while (true)
+ {
+ if (!parser.parse())
+ {
+ Thread.sleep(NO_ACTIVITY_SLEEP_MS);
+ if (!remoteApi.isRunning())
+ break;
+ }
+ }
+ }
+
+ // parse remaining messages
{
long lastDataMs = System.currentTimeMillis();
{
if (parser.parse())
lastDataMs = System.currentTimeMillis();
- else if (!remoteApi.isRunning())
+ else
{
final long timeSinceLastDataMs = System.currentTimeMillis()-lastDataMs;
if (timeSinceLastDataMs > NO_DATA_TIMEOUT_MS)
break; // Assume no data is available for reading any more
+
+ // Remote is dead, wait a bit until trying to read again
+ Thread.sleep(REMOTE_DEAD_SLEEP_MS);
}
- else
- Thread.sleep(NO_ACTIVITY_SLEEP_MS);
}
}
private Context m_context;
private String m_processName;
private String m_logFileName;
+ private boolean m_canBeRunning;
public RemoteAPI (Context context, String logFileName) {
m_context = context;
m_processName = m_context.getPackageName() + ":testercore";
m_logFileName = logFileName;
+ m_canBeRunning = false;
}
private ComponentName getDefaultTesterComponent () {
return false;
}
+ m_canBeRunning = true;
return true;
}
public boolean kill () {
ActivityManager.RunningAppProcessInfo processInfo = findProcess(m_processName);
+ // \note not mutating m_canBeRunning yet since process does not die immediately
+
if (processInfo != null) {
Log.d(LOG_TAG, "Killing " + m_processName);
Process.killProcess(processInfo.pid);
}
public boolean isRunning () {
- return isProcessRunning(m_processName);
+ if (!m_canBeRunning) {
+ return false;
+ } else if (isProcessRunning(m_processName)) {
+ return true;
+ } else {
+ // Cache result. Safe, because only start() can spawn the process
+ m_canBeRunning = false;
+ return false;
+ }
}
public String getLogFileName () {