diff options
author | Ray Donnelly <[email protected]> | 2012-12-10 23:49:46 +0000 |
---|---|---|
committer | Daniel Teske <[email protected]> | 2012-12-13 12:07:40 +0100 |
commit | 9917f9a71ba7d7d9bf9cb3fb79eda90913c4730d (patch) | |
tree | e4360246e75a4bd077597efda9cf8641430c95ee /src/plugins/android/androidrunner.cpp | |
parent | f6a499a18f5c5cf660390a4dfaf348fd9fe759c1 (diff) |
Fix Android ps output processing when ps is really busybox.
Usually, on Android, ps is a link to the toolbox program, but on
custom ROMs it's often a link to busybox instead. In this case
we must use "ps -w" or "ps w" to prevent it from truncating the
output and we must also interpret the output differently as the
PID column differs too (1st column with busybox, 2nd with toolbox)
Conflicts:
src/plugins/android/androidrunner.cpp
Change-Id: Ia6881104155b8f7e39edbee00fbe93fd6f9d9a68
Reviewed-by: Daniel Teske <[email protected]>
Diffstat (limited to 'src/plugins/android/androidrunner.cpp')
-rw-r--r-- | src/plugins/android/androidrunner.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/plugins/android/androidrunner.cpp b/src/plugins/android/androidrunner.cpp index 6339386d1f7..54d840aa549 100644 --- a/src/plugins/android/androidrunner.cpp +++ b/src/plugins/android/androidrunner.cpp @@ -74,19 +74,36 @@ AndroidRunner::~AndroidRunner() void AndroidRunner::checkPID() { QProcess psProc; + QLatin1String psCmd = QLatin1String("ps"); + QLatin1String psPidRx = QLatin1String("\\d+\\s+(\\d+)"); + + // Detect busybox, as we need to pass -w to it to get wide output. psProc.start(AndroidConfigurations::instance().adbToolPath().toString(), QStringList() << QLatin1String("-s") << m_deviceSerialNumber - << QLatin1String("shell") << QLatin1String("ps")); + << QLatin1String("shell") << QLatin1String("readlink") << QLatin1String("$(which ps)")); if (!psProc.waitForFinished(-1)) { psProc.terminate(); return; } + QByteArray which = psProc.readAll(); + if (which.startsWith("busybox")) { + psCmd = QLatin1String("ps -w"); + psPidRx = QLatin1String("(\\d+)"); + } + + psProc.start(AndroidConfigurations::instance().adbToolPath().toString(), + QStringList() << QLatin1String("-s") << m_deviceSerialNumber + << QLatin1String("shell") << psCmd); + if (!psProc.waitForFinished(-1)) { + psProc.kill(); + return; + } + QRegExp rx(psPidRx); qint64 pid = -1; QList<QByteArray> procs = psProc.readAll().split('\n'); foreach (const QByteArray &proc, procs) { if (proc.trimmed().endsWith(m_packageName.toLatin1())) { - QRegExp rx(QLatin1String("(\\d+)")); - if (rx.indexIn(QLatin1String(proc), proc.indexOf(' ')) > 0) { + if (rx.indexIn(QLatin1String(proc)) > -1) { pid = rx.cap(1).toLongLong(); break; } @@ -105,8 +122,7 @@ void AndroidRunner::checkPID() m_gdbserverPID = -1; foreach (const QByteArray &proc, procs) { if (proc.trimmed().endsWith("gdbserver")) { - QRegExp rx(QLatin1String("(\\d+)")); - if (rx.indexIn(QLatin1String(proc), proc.indexOf(' ')) > 0) { + if (rx.indexIn(QLatin1String(proc)) > -1) { m_gdbserverPID = rx.cap(1).toLongLong(); break; } |