diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2022-03-18 18:25:42 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2022-03-22 11:42:11 +0000 |
commit | 2846bef563294226d71634167dfaa9271cf1c460 (patch) | |
tree | 4f92a932f285e6a7d3863aca1ede10d21624795d | |
parent | 137d3367cff2ca9e61d58599e1cf16bc5751589d (diff) |
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>
-rw-r--r-- | src/plugins/android/androidrunnerworker.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index 2adc7eaa61..5da5d99ec2 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -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 { |