static int extractPid(const QByteArray &psOutput) { static const QByteArray needle("apitrace.github.io.eglretrace\r"); const int to = psOutput.indexOf(needle); if (to == -1) return -1; const int from = psOutput.lastIndexOf('\n', to); if (from == -1) return -1; return extractPidFromChunk(psOutput, from); }
void AndroidRunner::forceStop() { QProcess proc; proc.start(m_adb, selector() << _("shell") << _("am") << _("force-stop") << m_packageName); proc.waitForFinished(); // try killing it via kill -9 const QByteArray out = runPs(); int from = 0; while (1) { const int to = out.indexOf('\n', from); if (to == -1) break; QString line = QString::fromUtf8(out.data() + from, to - from - 1); if (line.endsWith(m_packageName) || line.endsWith(m_gdbserverPath)) { int pid = extractPidFromChunk(out, from); adbKill(pid); } from = to + 1; } }