diff --git a/src/plugins/android/androidrunner.cpp b/src/plugins/android/androidrunner.cpp index 08f7be5bfd2..a2c642af230 100644 --- a/src/plugins/android/androidrunner.cpp +++ b/src/plugins/android/androidrunner.cpp @@ -55,7 +55,7 @@ AndroidRunner::AndroidRunner(QObject *parent, ProjectExplorer::RunMode runMode) : QThread(parent) { - m_wasStarted = false; + m_tries = 0; Debugger::DebuggerRunConfigurationAspect *aspect = runConfig->extraAspect(); const bool debuggingMode = runMode == ProjectExplorer::DebugRunMode; @@ -153,13 +153,36 @@ QByteArray AndroidRunner::runPs() void AndroidRunner::checkPID() { - if (!m_wasStarted) - return; QByteArray psOut = runPs(); m_processPID = extractPid(m_packageName, psOut); + if (m_processPID == -1) { - m_checkPIDTimer.stop(); - emit remoteProcessFinished(tr("\n\n'%1' died.").arg(m_packageName)); + if (m_wasStarted) { + m_wasStarted = false; + m_checkPIDTimer.stop(); + emit remoteProcessFinished(tr("\n\n'%1' died.").arg(m_packageName)); + } else { + if (++m_tries > 3) + emit remoteProcessFinished(tr("\n\nUnable to start '%1'").arg(m_packageName)); + } + } else if (!m_wasStarted){ + if (m_useCppDebugger) { + // This will be funneled to the engine to actually start and attach + // gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below. + QByteArray serverChannel = ':' + QByteArray::number(m_localGdbServerPort); + emit remoteServerRunning(serverChannel, m_processPID); + } else if (m_useQmlDebugger) { + // This will be funneled to the engine to actually start and attach + // gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below. + QByteArray serverChannel = QByteArray::number(m_qmlPort); + emit remoteServerRunning(serverChannel, m_processPID); + } else if (m_useQmlProfiler) { + emit remoteProcessStarted(m_qmlPort); + } else { + // Start without debugging. + emit remoteProcessStarted(-1, -1); + } + m_wasStarted = true; } } @@ -189,7 +212,6 @@ void AndroidRunner::forceStop() void AndroidRunner::start() { m_adbLogcatProcess.start(m_adb, selector() << _("logcat")); - m_wasStarted = false; QtConcurrent::run(this, &AndroidRunner::asyncStart); } @@ -294,33 +316,9 @@ void AndroidRunner::asyncStart() } - QByteArray psOut = runPs(); - m_processPID = extractPid(m_packageName, psOut); - - if (m_processPID == -1) { - emit remoteProcessFinished(tr("Unable to start '%1'.").arg(m_packageName)); - return; - } - + m_tries = 0; + m_wasStarted = false; QMetaObject::invokeMethod(&m_checkPIDTimer, "start"); - - m_wasStarted = true; - if (m_useCppDebugger) { - // This will be funneled to the engine to actually start and attach - // gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below. - QByteArray serverChannel = ':' + QByteArray::number(m_localGdbServerPort); - emit remoteServerRunning(serverChannel, m_processPID); - } else if (m_useQmlDebugger) { - // This will be funneled to the engine to actually start and attach - // gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below. - QByteArray serverChannel = QByteArray::number(m_qmlPort); - emit remoteServerRunning(serverChannel, m_processPID); - } else if (m_useQmlProfiler) { - emit remoteProcessStarted(m_qmlPort); - } else { - // Start without debugging. - emit remoteProcessStarted(-1, -1); - } } void AndroidRunner::handleRemoteDebuggerRunning() @@ -342,6 +340,7 @@ void AndroidRunner::stop() { QMutexLocker locker(&m_mutex); m_checkPIDTimer.stop(); + m_tries = 0; if (m_processPID != -1) { forceStop(); emit remoteProcessFinished(tr("\n\n'%1' terminated.").arg(m_packageName)); diff --git a/src/plugins/android/androidrunner.h b/src/plugins/android/androidrunner.h index 589f27ecd49..b18aee29d2f 100644 --- a/src/plugins/android/androidrunner.h +++ b/src/plugins/android/androidrunner.h @@ -87,6 +87,7 @@ private: QProcess m_adbLogcatProcess; QTimer m_checkPIDTimer; bool m_wasStarted; + int m_tries; QByteArray m_logcat; QString m_intentName;