Android: fix logcat retrieval on pre Android Nougat

Logcat on pre Android Nougat (API <= 23) was broken because the the
returned output from the adb command had lots of null characters \u0000
in the string, and thus the comparison against the deployed package
name was failing and the pid was always -1. This makes sure to remove
any null characters before the comparison and simplifies the code a bit.

Task-number: QTBUG-101673
Fixes: QTCREATORBUG-26732
Change-Id: I3f185eceab376dbb0f4f11cf628b71e058ee5583
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Assam Boudjelthia
2022-03-18 18:25:42 +02:00
parent 137d3367cf
commit 2846bef563

View File

@@ -88,18 +88,15 @@ static bool isTimedOut(const chrono::high_resolution_clock::time_point &start,
return timedOut;
}
static qint64 extractPID(const QByteArray &output, const QString &packageName)
static qint64 extractPID(const QString &output, const QString &packageName)
{
qint64 pid = -1;
foreach (auto tuple, output.split('\n')) {
tuple = tuple.simplified();
if (!tuple.isEmpty()) {
auto parts = tuple.split(':');
QString commandName = QString::fromLocal8Bit(parts.first());
if (parts.length() == 2 && commandName == packageName) {
pid = parts.last().toLongLong();
break;
}
for (const QString &tuple : output.split('\n')) {
// Make sure to remove null characters which might be present in the provided output
const QStringList parts = tuple.simplified().remove('\0').split(':');
if (parts.length() == 2 && parts.first() == packageName) {
pid = parts.last().toLongLong();
break;
}
}
return pid;
@@ -126,7 +123,7 @@ static void findProcessPID(QFutureInterface<qint64> &fi, QStringList selector,
QtcProcess proc;
proc.setCommand({adbPath, args});
proc.runBlocking();
const QByteArray out = proc.allRawOutput();
const QString out = proc.allOutput();
if (preNougat) {
processPID = extractPID(out, packageName);
} else {